0

With my code which is just a regular RAW input example.... WM_INPUT, RIM_TYPEMOUSE... I'm getting on Windows 10 the full 1,000Hz of my mouse and on Windows 11 I'm getting about 128Hz.

How to fix this so it works with full 1,000Hz on Windows 11?

Should I be using buffered read of RawInputData?

static LRESULT CALLBACK HiddenWndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) {
    if ( msg == WM_INPUT ) {
        UINT dwSize = 0;
        GetRawInputData( (HRAWINPUT)lParam, RID_INPUT, nullptr, &dwSize, sizeof( RAWINPUTHEADER ) );
        BYTE* lpb = new BYTE[dwSize];

        if ( GetRawInputData( (HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof( RAWINPUTHEADER ) ) != dwSize ) {
            delete[] lpb;
            return DefWindowProc( hwnd, msg, wParam, lParam );
        }

        RAWINPUT* raw = (RAWINPUT*)lpb;
        if ( raw->header.dwType == RIM_TYPEMOUSE ) {
            _MouseData md = mousedata.load();

            md.dx += raw->data.mouse.lLastX;
            md.dy += raw->data.mouse.lLastY;
            md.dw += (*(short*)&raw->data.mouse.usButtonData) / WHEEL_DELTA;
            md.tick += 1;

            mousedata.store( md );

            // printf( "X: %i, Y: %i, W: %i\n", raw->data.mouse.lLastX, raw->data.mouse.lLastY, (*(short*)&raw->data.mouse.usButtonData) / WHEEL_DELTA );
        }

        delete[] lpb;
    }

        . . .
    return DefWindowProc( hwnd, msg, wParam, lParam );
}
static HWND CreateHiddenMessageWindow( HINSTANCE hInst ) {
    const wchar_t CLASS_NAME[] = L"HiddenRawInputWindow";

    WNDCLASS wc = {};
    wc.lpfnWndProc = HiddenWndProc;
    wc.hInstance = hInst;
    wc.lpszClassName = CLASS_NAME;
    RegisterClass( &wc );

    // MESSAGE-ONLY window (no visible UI)
    HWND hwnd = CreateWindowEx(
        0, CLASS_NAME, L"test", 0,
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
        nullptr, nullptr, hInst, nullptr
    );

    return hwnd;
}

static int _RegisterRawMouse( HWND hwnd ) {
    // Register for all HID input (generic)
    RAWINPUTDEVICE rid[1] = {};
     
    rid[0].usUsagePage = 0x01;
    rid[0].usUsage = 0x02;
    rid[0].dwFlags = RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE | RIDEV_INPUTSINK;
    rid[0].hwndTarget = hwnd;

    if ( not RegisterRawInputDevices( rid, 1, sizeof( RAWINPUTDEVICE ) ) ) {
        return 1;
    }
    return 0;
}
while ( PeekMessage( &msg, nullptr, 0, 0, PM_REMOVE ) ) {
    TranslateMessage( &msg );
    DispatchMessage( &msg );
}
New contributor
Gr3g is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • Hard to see how you're measuring the performance with the code provided. At any rate, start by removing the expensive heap allocations from the code path you want to run as fast as possible. Commented yesterday

1 Answer 1

0

the issue was that the window needs to be in focus to get the full 1000 WM_INPUTs on windows 11 which is different to how win10 was where you can get that many regardless of focus

New contributor
Gr3g is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Sign up to request clarification or add additional context in comments.

2 Comments

Great that you found a solution. Did you find the answer on a another post or website? In the future, please add a link to any references to help out other users that might have the same issue.
while this is the answer to my original question it doesn't help me much since I need 1000hz in the background... so yea, results are purely from testing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.