I want to trap the mouse in the middle of the window (like in an FPS game) using SetCursorPos.
The problem is that when I do, my window receives a WM_MOUSEMOVE -- which at best cancels out any movement that the user intended, and at worst enters a feedback loop.
I've considered reading the position using GetCursorPos and ignoring the message if it's the same as where I'd moved it with SetCursorPos. The problem with this approach though is that the mouse is asynchronous. If the program ever gets behind, then GetCursorPos will return a value different from what I'd expected -- and so it won't know to ignore the message.
Is there a good way to deal with this problem?
This sort of input should be done with the RawInput API and the cursor hidden when you app has focus. This means it is not bounded by the screen and you don't actually deal with the mouse events.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With