Question

I am currently using the RawInput API from Windows to get access to keyboard and mouse input. One thing i am a little bit confused about is when i register my mouse as a RawInputDevice i cannot move my Win32 window or use the controls up there (close, minimize etc...). Instead i get a loading icon cursor. Is this normal behaviour? This is how i register my device:

    RAWINPUTDEVICE Rid[2];

    Rid[0].usUsagePage = 0x01;
    Rid[0].usUsage = 0x02;
    Rid[0].dwFlags = RIDEV_NOLEGACY;   // adds HID mouse and also ignores legacy mouse messages
    Rid[0].hwndTarget = windowHandle;

    Rid[1].usUsagePage = 0x01;
    Rid[1].usUsage = 0x06;
    Rid[1].dwFlags = RIDEV_NOLEGACY;   // adds HID keyboard and also ignores legacy keyboard messages
    Rid[1].hwndTarget = windowHandle;

    if (RegisterRawInputDevices(Rid, 2, sizeof(Rid[0])) == FALSE) {
         // smth went wrong.
    }

And this is how i handle the WM_INPUT case:

case WM_INPUT:
    char buffer[sizeof(RAWINPUT)] = {};
    UINT size = sizeof(RAWINPUT);
    GetRawInputData(reinterpret_cast<HRAWINPUT>(lParam), RID_INPUT, buffer, &size, sizeof(RAWINPUTHEADER));
    RAWINPUT* raw = reinterpret_cast<RAWINPUT*>(buffer);
    if (raw->header.dwType == RIM_TYPEMOUSE || raw->header.dwType == RIM_TYPEKEYBOARD) {
        inputManager.processMessage(*raw);
    }
    break;

Is there something wrong?

Was it helpful?

Solution

You are setting the RIDEV_NOLEGACY flag. This disables legacy mouse messages.

Hence the default window procedure doesn't receive mouse messages. So it can't move your window, or respond to button clicks, or whatever. Which is what you are seeing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top