Mouse movement across any control

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!)
ssdjgru1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Joni KettunenSenior Software EngineerCommented:
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 (http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20918405.html?query=idle&topics=327)

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

Or idle time tracking (http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20933068.html?query=idle&topics=327).

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ssdjgru1Author Commented:
Thank you for your anwser!

If you are satisfied with 32 points, I am accepting your anwser right now ;)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.