Results 1 to 2 of 2

Thread: WM_INPUT messages capture with winEventFilter

  1. #1
    Join Date
    Feb 2013
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default WM_INPUT messages capture with winEventFilter

    Hello!
    I use class which inherits QApplication and implements its own winEventFilter(MSG* msg, long* result) to capture WM_INPUT messages and to process raw input data from keyboard in Qt 4.8.4.
    Qt Code:
    1. bool Application::winEventFilter(MSG *msg, long *result)
    2. {
    3. UINT dwSize;
    4. WCHAR keyChar;
    5. switch(msg->message)
    6. {
    7. case WM_INPUT:
    8. {
    9. if (GetRawInputData((HRAWINPUT)msg->lParam,
    10. RID_INPUT,
    11. NULL,
    12. &dwSize,
    13. sizeof(RAWINPUTHEADER)) == -1) return false;
    14. LPBYTE lpb = new BYTE[dwSize];
    15. if (lpb == NULL) return false;
    16. if (GetRawInputData((HRAWINPUT)msg->lParam,
    17. RID_INPUT,
    18. lpb,
    19. &dwSize,
    20. sizeof(RAWINPUTHEADER)) != dwSize)
    21. {
    22. delete[] lpb;
    23. return false;
    24. }
    25. PRAWINPUT raw = (PRAWINPUT)lpb;
    26. UINT Event;
    27. Event = raw->data.keyboard.Message;
    28. keyChar = GetSymbol(raw->data.keyboard.VKey);
    29. char keyCharLO = (char)keyChar;
    30. delete[] lpb;
    31. if (!iswprint(keyChar))
    32. return false;
    33. // process data from keyboard
    34. keyStrokeHandle->ProcessNextKeyStroke(Event, keyChar);
    35.  
    36. *result = 0;
    37. QApplication::winEventFilter(msg, result);
    38. return true;
    39. }
    40. default:
    41. {
    42. return false;
    43. }
    44. }
    45. }
    To copy to clipboard, switch view to plain text mode 
    After RegisterRawInputDevices call, application starts to recieve WM_INPUT messages.
    The problem is: when user types in qt application, data from keyboard don't get to input which is used to type data, it is "blocked" by winEventFilter.
    According to Qt Documentation:
    If you don't want the event to be processed by Qt, then return true and set result to the value that the window procedure should return. Otherwise return false.
    And MSDN:
    Return value
    If an application processes this message, it should return zero.
    But I can't receive my input in application whether I return true/false from winEventFilter, change *result value or invoke inhedited QApplcation::winEventFilter.
    What do I have to do to get data in application after WM_INPUT processing?

  2. #2
    Join Date
    Feb 2013
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: WM_INPUT messages capture with winEventFilter

    The answer to my question is not related to Qt.
    Wrong flags of RAWINPUTDEVICE structure were my problem. I used RIDEV_NOLEGACY flag, so legacy keyboard messages were not generated. Avoid it to get data to your application.
    If RIDEV_NOLEGACY is set for a mouse or a keyboard, the system does not generate any legacy message for that device for the application. For example, if the mouse TLC is set with RIDEV_NOLEGACY, WM_LBUTTONDOWN and related legacy mouse messages are not generated. Likewise, if the keyboard TLC is set with RIDEV_NOLEGACY, WM_KEYDOWN and related legacy keyboard messages are not generated.
    Qt Code:
    1. RAWINPUTDEVICE rid;
    2. rid.dwFlags = 0; // I've used RIDEV_NOLEGACY here
    3. rid.usUsagePage = 1;
    4. // only raw keyboard data
    5. rid.usUsage = 6;
    6. rid.hwndTarget = windowId;
    7. RegisterRawInputDevices(&rid, 1, sizeof(rid));
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. WM_INPUT not being filtered by winEventFilter()
    By been_1990 in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2010, 03:19
  2. Printing Messages Only once
    By purplecoast in forum Qt Programming
    Replies: 0
    Last Post: 3rd October 2010, 21:15
  3. Getting messages sent by PostMessage
    By Luc4 in forum Qt Programming
    Replies: 5
    Last Post: 19th May 2010, 16:13
  4. Replies: 1
    Last Post: 18th March 2010, 08:42
  5. Replies: 3
    Last Post: 5th July 2009, 17:22

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.