Archived

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

Help with DirectInput Mouse

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

TOTWGPG book didn''t explain how the mouse works very clearly. I was able to understand that it uses relative mouse position. But I want to know how to get absolute value (the exact x and y coordinates of the cursor) of the mouse. But it don''t tell me how. If it is not a good way to use the mouse, tell me why. This code don''t work real well: static int mousex = (SCREEN_WIDTH/2)-1; //static because its function variable that I want to keep static int mousey = (SCREEN_HEIGHT/2)-1; mousex += mousestate.lX; mousey += mousestate.lY; if(mousex >= SCREEN_WIDTH) mousex = SCREEN_WIDTH - 1; else if(mousex < 0) mousex = 0; if(mousey >= SCREEN_HEIGHT) mousey = SCREEN_HEIGHT - 1; else if(mousey < 0) mousey = 0; if(mousex >= 0 && mousex <= 151 && mousey >= 0 && mousey <= 20) { ... } it don''t work right. If I move my cursor to the edge of screen (the right or bottom) the mouse coordinates seem to go off screen? Help is real apprecriated. ______________________________________________ You know your game is in trouble when your AI says, in a calm, soothing voice, "I''m afraid I can''t let you do that, Dave"

Share this post


Link to post
Share on other sites
Well, i was wondering why did you made a verification of the offscreen coordinates of the screen two times? First you made a verification to see if the mouse is offset, and if it is then make it onset... Well the last verification you used numbers (151 and 20) and in the first verifications you used SCREEN_WIDTH and SCREEN_HEIGHT... try to use only one number since 151 maybe is not the SCREEN_xxxx values...

And if you verify the mousex position and mousey position once, its not needed to make another verification later...

"here its verifying offsets..." "here it uses SCREEN_WIDTH..."
if(mousex >= SCREEN_WIDTH)
mousex = SCREEN_WIDTH - 1;
else if(mousex < 0)
mousex = 0;

"an here again???" "and here 151???"
if(mousex >= 0 && mousex <= 151 && mousey >= 0 && mousey <= 20)


To code is to make things come to life

Share this post


Link to post
Share on other sites
Sorry, I thought this thread faded away. I fixed the problem by ShowCursor(FALSE); and then making my own cursor. I found out by comparing windows and my cursor, windows moves faster and isn''t accurate for my game, and my cursor is right on spot. The 2nd checking is for button, I wanted to see if the mouse is over the button, if so, then I want to highlight the button. It''s all working perfectly now. Thanks anyway!

______________________________________________
You know your game is in trouble when your AI says, in a calm, soothing voice, "I''m afraid I can''t let you do that, Dave"

Share this post


Link to post
Share on other sites