Microsoft seems to recommend using WM_INPUT for input. I want to only get relative mouse input and hide the mouse cursor all together for a short while (For gesture based input). However, using RIDEV_CAPTUREMOUSE|RIDEV_NOLEGACY while registering the input device only prevents the mouse clicks to other windows, but the mouse cursor is still visible and not constrained to my window. How can I hide it and make it reappear exactly where I left off when my input capture began after the short while?

I know this has been asked before in the context of FPS controls, but it always seemed to be in a different context, mostly with APIs that already implement a mouse grab like this.

It was also mentioned that you could hide the cursor and reset it to its window's center after every move. However, AFAIR, DirectInput let you grab the mouse cursor exclusively. So since that was deprecated in favor of WM_INPUT, is the "old way" without DX the way to go again, or is there something new that works well with WM_INPUT?

Thank you!


2 Answers 2


If I understand you correctly, you simply want to hide the mouse when your gesture starts, and then make the mouse appear again on the position it disappeared.

Get the mouse position before hiding:

POINT posRelative;
POINT posAbsolute;
posRelative.x = posAbsolute.x;
posRelative.y = posAbsolute.y;
ScreenToClient(hwnd, &posRelative);

then show / hide it:

bool hideCursor = true;
while(hideCursor  != IsRealCursorHidden())
    ShowCursor(hideCursor  ? 0 : 1);

bool IsRealCursorHidden()
    int internalCount = ShowCursor(0);
    internalCount = ShowCursor(1);
    return (internalCount < 0 ) ? true : false;

and then show the cursor at the desired original position again:

SetCursorPos(pos.x, pos.y);


GetCursorPos will be in screen space, so if you have a different resolution you will have to take that into account.

  • \$\begingroup\$ This plus registering/unregistering my mouse with WM_INPUT is pretty much what I ended up doing. Seems to work just well. I just store the mouse in screen-coordinates and pretty much ignore resolution changes while I am in relative mode. \$\endgroup\$
    – ltjax
    Mar 30, 2013 at 11:49
  • \$\begingroup\$ since i'm using this with an opengl setup i don't know if there is a special directx solution, but over the years microsoft also cut back all those special solutions, because these basic functions do the job good \$\endgroup\$
    – cppanda
    Mar 30, 2013 at 14:12

The advantage to using WM_INPUT is that your game receives raw data from the mouse at the lowest level possible.

WM_INPUT is only for raw input, it doesn't know of or care about the cursor and absolute coordinates. Cursor specific things are specific to the windowing system, so for PC you can use the standard methods of manipulating the cursor. It is C# but translating it to unmanaged code shouldn't be hard.

[DllImport("user32.dll", EntryPoint = "SetCursorPos")]
public extern static Int32 SetCursorPosition(Int32 x, Int32 y);

static extern int ShowCursor(bool bShow);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .