[Last Call] Learn how to a build a cloud-first strategyRegister Now


Mouse movement across any control

Posted on 2006-03-27
Medium Priority
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

Accepted Solution

Joni Kettunen earned 128 total points
ID: 16299954
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:
  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).

Author Comment

ID: 16299992
Thank you for your anwser!

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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

834 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