How to emulate keystroke F1 for use in Qt/MFC Migration Framework solution?

The code sample below shows how to emit a F1 key stroke from the QPushButton::clicked() [doc.qt.nokia.com] signal (in your Qt application) when wanting your MFC parent application to receive it (not your Qt application). The example uses the Windows API to achieve this:

  1. #ifdef WIN32
  2. #include <windows.h>
  3. #endif
  4.  
  5. void CMyQtDlg::on_btn_help_clicked()
  6. {
  7. #ifdef WIN32
  8.     if (parentWidget())
  9.     {
  10.         PostMessage(parentWidget()->winId(), WM_KEYDOWN, VK_F1, 0);
  11.         PostMessage(parentWidget()->winId(), WM_KEYUP, VK_F1, 0);
  12.     }
  13. #endif
  14. }  

No comments

Write a comment

Sorry, you must be logged in to post a comment.