• Advertisement

Archived

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

Windows API: Cursor

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

I have a problem that I assume has an obvious solution, since most commercial games deal with it. High level description: I want to capture mouse motion without being limited by cursor position. Mouse motion will control rotation in my program, and I''d like the user to be able to rotate infinitely in a particular direction without stopping. So, for example, I don''t want to have rotation stop when the cursor would normally hit the edge of the screen. My solution idea: First off, I hide the cursor using ShowCursor(FALSE). My idea was to do the following: - use SetCursor to place the cursor in the middle of the screen - on a WM_MOUSEMOVE event, find the difference in mouse position from the centre of the screen, then use SetCursor to put the cursor back in the middle This logic doesn''t actually seem to work . Is there a better way of doing this? Or is my implementation flawed? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Maybe you should first store the mouse position to variables and when button(rotation motion starts) is pressed, then just Set the mouse pos to thoes coords long as needed.

Share this post


Link to post
Share on other sites
using direct input you can get the amount the mouse was moved since the last call of the function....its called mouse mikeys or something like that....it works even if the cursor is stopped at the edge of the screen


"A soldier is a part of the 1% of the population that keeps the other 99% free" - Lt. Colonel Todd, 1/38th Infantry, Ft. Benning, GA

Share this post


Link to post
Share on other sites
Thanks for the input guys. I solved the problem.

If I reset the cursor position in the WM_MOUSEMOVE handler, I create an infinite loop of MOUSEMOVE messages that locks up the application. The solution is to not handle WM_MOUSEMOVE, and instead read and reset the mouse position just before render time (i.e. on the WM_PAINT message). This way there''s no cycle of mouse-related messages and hence no lockups.

Share this post


Link to post
Share on other sites
That''s because SetCursorPos() sends another WM_MOUSEMOVE message to your program, which in turn calls SetCursorPos() again, etc. It''s an infinite recursion.

Share this post


Link to post
Share on other sites

  • Advertisement