Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to re-direct keyboard events from Qt to Win32 windows?
Forum Updated to NodeBB v4.3 + New Features

How to re-direct keyboard events from Qt to Win32 windows?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 5.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RogerCui
    wrote on last edited by
    #1

    Hi, I have a Qt window, its parent is a Win32 window.
    I want to re-direct all keyboard events to the Win32 window, e.g. let it handle application shortcuts.

    The code is like this,
    @
    class QChild : public QWidget
    {
    pulibc:

    void keyPressEvetn(QKeyEvent* e)
    {
    int key = e->key;
    // TODO: WM_KEYDOWN message needs two parameters, I'm not sure how to construct lParam from Qt.
    // Are there some Qt utilities can do this?
    }
    }
    @

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Hi,

      I think, what you need is the following:

      @
      class QChild : public QWidget
      {
      public:
      bool winEvent(MSG* message, long* result)
      {
      if(WM_KEYDOWN == message->message)
      {
      HWND hWndParent = ::GetParent(WinId());
      if(0 != hWndParent)
      *result = ::SendMessage(, message->message, message->lParam, message->wParam);
      }
      }
      }
      @

      Building the correct WPARAM for the WM_KEYDOWN event is not so easy, as it contains scan codes etc ("WM_KEYDOWN on MSDN":http://msdn.microsoft.com/en-us/library/ms646280(VS.85).aspx ). Make sure to also foreward the WM_KEYUP event. You could also just do a filtering before forewarding etc.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RogerCui
        wrote on last edited by
        #3

        it works, thanks!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved