today I want to ask a question about how to get mouse movement value with DirectX Tool Kit.

While I can certainly use Mouse::SetMode(MODE_RELATIVE), to do this, I want to be able to get the mouse cursor position at the same time (which can only be done with MODE_ABSOLUTE).

The method I thought of involves leaving mouse mode as the default MODE_ABSOLUTE, and then subtract the mouse position from the previous frame from that of the current one.
But with this method, the mouse cursor can jump out of the window.

So I thought of restricting the mouse cursor to a certain point, but this obviously prevents me from calculating the movement value with said method.

Does anyone have some ideas on how to achieve this with DirectX Tool Kit ?
Or am I missing some obvious thing ?

Thanks in advance!

  • 1
    \$\begingroup\$ Generally speaking, you either use absolute coordinates -or- you use relative mouse coordinates. Both at the same time isn't particularly useful. If you do need both, then you should just keep it in the absolute mode and keep track of the previous frame's x/y location to compute the delta. \$\endgroup\$ – Chuck Walbourn Aug 14 '15 at 6:06

If I am understanding the question correctly, you just want the delta mouse when you are in relative mode.
According to the docs,


When you query the state of the mouse, the x and y coordinates return the delta.

Note, because you are in relative mode and the mouse is locked, the mouse is likely always in the center of the window so any fixed position is worthless. (You could always use the native APIs to get it's true position if you so desire)

| improve this answer | |
  • 1
    \$\begingroup\$ For Windows desktop, Mouse uses WM_INPUT so the system mouse cursor is hidden and 'locked' to the applications window. When you return to absolute mode, I move the mouse to the position it was at when you entered relative mode. For Windows Runtime apps, the system cursor position is 'locked' in the last position it was before entering relative mode as well. \$\endgroup\$ – Chuck Walbourn Aug 14 '15 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.