Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Better way for Detacting Mouse Movement

Better way for Detacting Mouse Movement

Scheduled Pinned Locked Moved C#
helpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brad Wick
    wrote on last edited by
    #1

    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); }

    M 1 Reply Last reply
    0
    • B Brad Wick

      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); }

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      You can create a Rectangle 10 pixels wide and 10 pixels high around mouseCoords and then use Rectangle.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...

      B 1 Reply Last reply
      0
      • M mav northwind

        You can create a Rectangle 10 pixels wide and 10 pixels high around mouseCoords and then use Rectangle.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...

        B Offline
        B Offline
        Brad Wick
        wrote on last edited by
        #3

        That sounds like a good idea, but I dont know anything about that. Can you help by providing any code examples?

        M 1 Reply Last reply
        0
        • B Brad Wick

          That sounds like a good idea, but I dont know anything about that. Can you help by providing any code examples?

          M Offline
          M Offline
          mav northwind
          wrote on last edited by
          #4

          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...

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups