Jump to content
  • Advertisement
Sign in to follow this  
ProgrammerZ

GetCursorPos?

This topic is 3801 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!