Archived

This topic is now archived and is closed to further replies.

How to check mouse position

This topic is 5113 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my program I'm currently using the WM_MOUSEMOVE in my windows procedure function to check for mouse movements. I would like to be able to check the mouse position whenever I want instead of waiting for the windows message. For instance, I've already done this with the keyboard using the macro: #define KEY_DOWN(vKey) (GetAsyncKeyState(vKey) & 0x8000) ? true : false Is there a similar way to do this for the mouse? [edited by - EvilProgrammer on December 13, 2003 9:26:39 PM]

Share this post


Link to post
Share on other sites
You could store the value of the mouse position in a variable every time you recieve the message, then check it whenever you want. I doubt that you''ll need the precision of over however many frames per second you''ll be running at.. probably rather high. I suppose the alternative is to use DirectInput for mouse control.

Share this post


Link to post
Share on other sites
There does seem to be some lag, though. It happens when I'm moving the character on the screen and looking around a lot(using the mouse, it's a 3d game). I'd like to be able to do it without getting into directx. I tried directx before and I could never get it to work, so I decided to try to finish a game before trying to figure out directx.

[edited by - EvilProgrammer on December 13, 2003 11:08:22 PM]

Share this post


Link to post
Share on other sites
You can use the Windows API function GetCursorPos() to get the 2D screen coordinates of the mouse:

POINT mousePos;
GetCursorPos(&mousePos);

// mousePos.x is the x coordinate of the mouse,

// and mousePos.y is the y coordinate of the mouse

Share this post


Link to post
Share on other sites