Raw Input for mouse tracking always returns 0 for delta values

-1

Registered Raw Input Device doesn't give mouse delta, WM_INPUT does get triggered and it does pass the if(raw->header.dwType == RIM_TYPEMOUSE) statement, but values given are always 0

void InputSetup() {
    RAWINPUTDEVICE rid;
    rid.usUsagePage = HID_USAGE_PAGE_GENERIC;       //0x01
    rid.usUsage = HID_USAGE_GENERIC_MOUSE;          //0x02
    rid.dwFlags = RIDEV_INPUTSINK;                  //0x00000100
    rid.hwndTarget = hWnd_main;                     //Window Handle
    RegisterRawInputDevices(&rid, 1, sizeof(rid));  //Registring RID
}

LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {

    switch(uMsg){
        //...
        case WM_INPUT:
            UINT dwSize = 40;
            static BYTE lpb[40];

            GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER));

            RAWINPUT* raw = (RAWINPUT*)lpb;

            if (raw->header.dwType == RIM_TYPEMOUSE) {
                MouseDelta.x = raw->data.mouse.lLastX;
                MouseDelta.y = raw->data.mouse.lLastY;
            }
            break;
        //...
    }
}

MouseDelta Is always (0, 0). The WM_INPUT does trigger, but raw->data.mouse.lLastX and Y are always 0.

c++
winapi
raw-input
asked on Stack Overflow Jun 15, 2019 by DeltaJuliet2k • edited Jun 16, 2019 by Jeremy Friesner

1 Answer

1

Alright guys the problem were these lines:

UINT dwSize = 40;
static BYTE lpb[40];

just set them both to sizeof(RAWINPUT) and it will work I got that from msdn article but it turns out it was wrong

answered on Stack Overflow Jun 16, 2019 by DeltaJuliet2k • edited Jun 16, 2019 by DeltaJuliet2k

User contributions licensed under CC BY-SA 3.0