Detect user activity

J

Jesper, Denmark

Hi,

I want an app that I'm writing to be able to hide itself whenever it hasn't
been used for say 10 minutes.

Is there a smart way to detect user activity within an app. Kind of overall
message that I can hook up to so that I dont have to call some function to
register user activity in all my gui event handlers.

Jesper.
 
J

Jani Järvinen [MVP]

Hi Jesper,
I want an app that I'm writing to be able to hide itself whenever it
hasn't
been used for say 10 minutes. Is there a smart way to detect user
activity within an app?

I'm on the same lines as Peter; you would first need to define what you mean
by "using" your application. However, I've built several Windows
applications that needed a similar feature, and back then I used to define
the "using" as pressing keys and clicking the mouse. That used to be
accurate enough for my needs.

Depending on the application type you have (WinForms?), you could monitor
the messages important to you, and then have a timer (say) to checked
whether an inactivity counter has passed the ten minute limit. If it has,
then you could do something, for example close down network/database
connections, etc.

In WinForms forms you have the KeyPreview property, which helps with the
keyboard events. For the mouse I'm not aware of a similar, easy to use
feature, but you could create an application (Win32) hook to catch the mouse
messages centrally.

Hope this helps!

--
Regards,

Mr. Jani Järvinen
C# MVP
Vantaa, Finland
(e-mail address removed)
http://www.saunalahti.fi/janij/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top