How to tell if the mouse is moving in c#

Go To


Possible Duplicate:
XNA Mouse Movement

Basically, I am creating a game using XNA, and I need a way of telling if the mouse is moving. Any help is greatly appreciated. thanks in advance!

2012-04-03 21:33
by hazard1994


You can capture and store the mouse position in the Update() method of your game loop. Then, you can compare the stored mouse position with the current mouse position. If the values differ, the mouse has moved.

2012-04-03 21:40
by njebert
Thanks for the help - hazard1994 2012-04-04 14:54


Use MouseState and compare the previous MouseState to the current MouseState

MouseState currentMouseState = Mouse.GetState();
if (currentMouseState != originalMouseState)
    //The mouse did something

You could compare MouseState.X and MouseState.Y if you only care about movement

2012-04-03 21:39
by Murtnowski
I figured it out for myself, but thanks for the help anyway: - hazard1994 2012-04-04 14:54