PDA

View Full Version : WM_INPUT messages capture with winEventFilter



OriginalPrankst
3rd February 2013, 11:18
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.


bool Application::winEventFilter(MSG *msg, long *result)
{
UINT dwSize;
WCHAR keyChar;
switch(msg->message)
{
case WM_INPUT:
{
if (GetRawInputData((HRAWINPUT)msg->lParam,
RID_INPUT,
NULL,
&dwSize,
sizeof(RAWINPUTHEADER)) == -1) return false;
LPBYTE lpb = new BYTE[dwSize];
if (lpb == NULL) return false;
if (GetRawInputData((HRAWINPUT)msg->lParam,
RID_INPUT,
lpb,
&dwSize,
sizeof(RAWINPUTHEADER)) != dwSize)
{
delete[] lpb;
return false;
}
PRAWINPUT raw = (PRAWINPUT)lpb;
UINT Event;
Event = raw->data.keyboard.Message;
keyChar = GetSymbol(raw->data.keyboard.VKey);
char keyCharLO = (char)keyChar;
delete[] lpb;
if (!iswprint(keyChar))
return false;
// process data from keyboard
keyStrokeHandle->ProcessNextKeyStroke(Event, keyChar);

*result = 0;
QApplication::winEventFilter(msg, result);
return true;
}
default:
{
return false;
}
}
}

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?

OriginalPrankst
13th April 2013, 10:31
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.


RAWINPUTDEVICE rid;
rid.dwFlags = 0; // I've used RIDEV_NOLEGACY here
rid.usUsagePage = 1;
// only raw keyboard data
rid.usUsage = 6;
rid.hwndTarget = windowId;
RegisterRawInputDevices(&rid, 1, sizeof(rid));