Sign in to follow this  

GetCursorPos?

This topic is 3462 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

Hey....I've been working on a game engine, and I'm currently programming my input module. I looked at some posts and saw that, apparently, WM_MOUSEMOVE is the best way to get input from the cursor. However (correct me if I'm wrong), Windows will only send that message if the cursor moves. So, I was wondering if I could just use GetCursorPos instead and calculate the window offset with GetWindowRect. Is this a valid (but more importantly, recommended) method of getting cursor input? Feel free to elucidate! --ProgrammerZ

Share this post


Link to post
Share on other sites
GetCursorPos() with ScreenToClient() will give you the mouse cursor coordinates in client coordinates for a given window (keep in mind: they might be negative).

But why do this? Just trap WM_MOUSEMOVE and update an X and Y variable in your program and use those to get the current mouse position at any time.

Share this post


Link to post
Share on other sites
I think I should clarify something. I am storing the cursor position each frame, but what about on the first frame of the application? If the user doesn't move the cursor, how will I know what the initial position if the cursor is (the position of the cursor when the program starts)? Is it acceptable to use GetCursorPos in that case?

Share this post


Link to post
Share on other sites
Sure, or you simply reset it to, say, the center of the window ;)

There's really nothing wrong with GetCursorPos. It's just a tad faster to store the cursor pos instead of calling it everytime you want the coordinates. But to get the initial coordinates it's just fine, but again: keep in mind that the coordinates relative to the client window might be negative.

Share this post


Link to post
Share on other sites

This topic is 3462 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.

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