Move the mouse cursor without starting WM_MOUSEMOVE

I want to lure the mouse in the middle of the window (for example, in the FPS game) using SetCursorPos .

The problem is that when I do this, my window receives WM_MOUSEMOVE, which at best cancels any movement that is intended for the user, and in the worst case enters into a feedback loop.

I considered reading the position using GetCursorPos and ignoring the message if it is the same as where I moved it using SetCursorPos. The problem with this approach is that the mouse is asynchronous. If the program ever lags, then GetCursorPos will return a value other than what I expected - and therefore it will not know to ignore the message.

Is there a good way to handle this problem?

+3
source share
1 answer

This type of input must be done using the RawInput API, and the cursor is hidden when the application has focus. This means that it is not limited to the screen, and you are not actually dealing with mouse events.

+4
source

All Articles