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 ); } 
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 Nov 21 at 11:07

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

5 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
You need 1000 mouse updates per second while your application is not even the foreground one? Really? What is your use case that causes that requirement? That seems rather odd to me.
Well... I'm analyzing mouse movement while playing games and thus needing the full accuracy that comes with my mouse and needing to be in foreground
@JesperJuhl That's the whole purpose of the RIDEV_INPUTSINK flag: Receiving input even when the caller is not in the foreground. The documentation doesn't call out that this would degrade fidelity. While it's still unclear how the OP measures performance, the assumption that input events are received with full resolution is well justified.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.