Better way for Detacting Mouse Movement
-
I am checking to see when a user moves their mouse but the problem is sometimes the mouse does not move and it thinks that it did. I think the mouse maybe really did move just one pixel so I want to ignore that mouse movement. Basically I am think that the mouse could move up, down, left or right 5 pixels from the original starting place and the system should think the mouse did not move. Can someone help me fix up my code? private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { // If mouseCoords is empty don't close the screen saver if(!mouseCoords.IsEmpty) { // If the mouse actually moved if(mouseCoords != new Point(e.X, e.Y)) { // Close this.Close(); } } // Set the new point where the mouse is mouseCoords = new Point(e.X, e.Y); }
-
I am checking to see when a user moves their mouse but the problem is sometimes the mouse does not move and it thinks that it did. I think the mouse maybe really did move just one pixel so I want to ignore that mouse movement. Basically I am think that the mouse could move up, down, left or right 5 pixels from the original starting place and the system should think the mouse did not move. Can someone help me fix up my code? private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { // If mouseCoords is empty don't close the screen saver if(!mouseCoords.IsEmpty) { // If the mouse actually moved if(mouseCoords != new Point(e.X, e.Y)) { // Close this.Close(); } } // Set the new point where the mouse is mouseCoords = new Point(e.X, e.Y); }
You can create a
Rectangle
10 pixels wide and 10 pixels high aroundmouseCoords
and then useRectangle.Contains()
to check whether the current mouse position still is inside the rect.Regards, mav -- Black holes are the places where God divided by 0...
-
You can create a
Rectangle
10 pixels wide and 10 pixels high aroundmouseCoords
and then useRectangle.Contains()
to check whether the current mouse position still is inside the rect.Regards, mav -- Black holes are the places where God divided by 0...
-
That sounds like a good idea, but I dont know anything about that. Can you help by providing any code examples?
Come on, that's not that hard. You should read up the class documentation for
Rectangle
where you'll find the neccessary constructor and method to perform the task. I really think it's a lot better if you come up with the solution yourself (with some help from CP) instead of spoon-feeding you with the complete code. (teach a man to fish...)Regards, mav -- Black holes are the places where God divided by 0...