Mouse movement across any control

Posted on 2006-03-27
Last Modified: 2010-04-16
I am trying to make an application that logs out if the user is inactive  (mouse hadn't moved) for certain time. Therefore I need to catch any mouse movement that occours over my program. The problem is that I would not like to make "onMouseMove" event for each and every control to reset the Time Out Timer. Is there a way to monitor the mouse for whole focused application?
(PS: Sorry for stingy points, but I put 500 points on another question, that I resolved myself and now waiting for refound - I will raise the award the moment I get back my points!)
Question by:ssdjgru1
    LVL 4

    Accepted Solution

    Do you want to find out idle time of user? There is an event to that.

    But first to your question. Yes, there is way to monitor mouse. One way is to call (in timer event for example) Control.MousePosition and see if it has moved since last call:

    private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
          Point oldPos = new Point();
          Point newPos = Control.MousePosition;
          if (newPos.X == oldPos.X && newPos.Y == oldPos.Y)
                // Mouse hasn't moved

    Of course mouse could be stashed away while user is in chat window or writing a mail. Therefore I suggest checking against idle time. You can bind Application.Idle EventHandler or idle time tracker.

    Good examples can be found within this forum:
    Application.Idle event handling (

    In Application class you have static event Idle, you can use it following way:
      Application.Idle += new EventHandler(this.OnIdle);
    private void OnIdle(object sender, System.EventArgs args)
    //Do anything you want, IDLE-TIME!!!

    Or idle time tracking (

    I hope this helps (and 32 points is fine for easy question like this).

    Author Comment

    Thank you for your anwser!

    If you are satisfied with 32 points, I am accepting your anwser right now ;)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now