Sign in to follow this  
Slider38

Mouse Trouble

Recommended Posts

Hi Folks, I recently bought a new computer and switched to WindowsXP (finally). My problem is that old programs that I had or were writing no longer seem to work as they apply to mouse control. Within my programs, the mouse position is very erratic. The more the mouse is moved, the more lost it becomes. The code I have successfully used in the past looks like this: int mouse_x, // used to track mouse mouse_y; A COUPLE OF GLOBALS TO TRACK THE MOUSE WITHIN MAIN: // get the input from the mouse lpdimouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mouse_state); // move the mouse cursor mouse_x+=(mouse_state.lX); mouse_y+=(mouse_state.lY); A CHECK OF THE MOUSE AND AN UPDATE OF IT'S POSITION if(mouse_x >= 639) { mouse_x = 639; SetCursorPos(mouse_x, mouse_y); } if (mouse_x < 0) { mouse_x = 0; SetCursorPos(mouse_x, mouse_y); } if(mouse_y >= 479) { mouse_y = 479; SetCursorPos(mouse_x, mouse_y); } if (mouse_y < 0) { mouse_y = 0; SetCursorPos(mouse_x, mouse_y); } BOUNDARY CHECKS if((mouse_y > 400)&&(mouse_state.rgbButtons[0])) THEN VARIOUS TESTS TO SEE IF THE USER IS PRESSING A BUTTON I'm stumped as to why this logic no longer works correctly. My old machine was a lot slower than the new one 900mg vs. 3g. Could the processor speed be impacting what's going on? Any suggestions on what's going on here would be appreciated. Thanks folks, Slider

Share this post


Link to post
Share on other sites
Your logic is highly resolution-dependent. If you're running this code at any resolution other than 640x480, you will get weird results.

Other than that, it's hard to know for sure without a better idea of what's going on. If you carefully, slowly, move the mouse to the left (but not up or down), what does the pointer do? Repeat for all four directions (be sure to start the program fresh each time). Can you find a specific behavior that is definitely wrong when just moving in one direction at a time? If so, are you missing some buffered input from DirectX or something similar?

Share this post


Link to post
Share on other sites
Sounds like you have a problem with Relative/Absolute axis modes. If the device is in relative axis mode then that code should work. If it's in absolute axis mode then the retrieved axis data is the actual position and should not be added to the accumulated position.

You can check this using IDirectInputDevice8::GetProperty() with the DIPROP_AXISMODE property.

Share this post


Link to post
Share on other sites

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