Sign in to follow this  
shwasasin

Relative Mouse Coordinates in Windows

Recommended Posts

Hey everyone, I'm working on a small project where I need to use relative mouse coordinates in Windows (MSVC, C++). Since I'm using GetAsyncKeyState for reading Mouse/Keyboard presses, I'd like something fairly lightweight (ideally in the Windows SDK). I've looked into using DirectInput, but it's considered deprecated. I've looked at Raw Input Data in Windows, but it seems like too much work to simply request 1 piece of information. I could figure out relative positioning based on the last position of the mouse, but when I leave the current window or hit the edge of the windows desktop it stops reporting data, so I'm stuck! Does anyone have any suggestions? Thanks!

Share this post


Link to post
Share on other sites
If you want to continue to get mouse messages after you've left your window, you can use the SetCapture Function.

You should call ReleaseCapture(), when you no longer need to track outside your window.

If you then want to translate the coordinates returned relative to your window, you can use MapWindowPoints.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this