User Inactivity Timer

  • Thread starter Thread starter Stanley Glass
  • Start date Start date
S

Stanley Glass

I am looking for a way to build in a timer that if the user does not do
something in a certain time the program forces them to close it down and
open it up or enter a password to continue. I know how to use the timer
object but how do I know if the user has done something within my app? Would
i have to stick with the idea of tracking every keystroke and mouse click?
Or is there another way? So far the only solution that i have come up with
would be to reset the timer with ever click of a key or mouse. Any other
ideas?

-Stanley
 
The hook in the sample will also keep the application open while the user is in
another program, not necessarily yours. This might be an issue for you. If you
are looking for security you probably want something along the lines of:

1. If the form is focused, and the user doesn't type for say 10 minutes, shut
the app out.
2. If the form is not focused, and the user is doesn't re-focus for say 5
minutes, shut the app out.

If you wanted this, you could place a WndProc override on your Forms to catch
keyboard and
mouse windows messages. Use these to reset your timer. In this case it becomes
a simple switch
statement. Something like this:

switch(wndMessage.Message) {
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_LBUTTONDBLCLK:
timer.Stop(); timer.Start();
base.WndProc(wndMessage);
}

For the focus you simply use the focus based events to start an alternate timer.


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

Stanley Glass said:
Anything in .NET? I'm not a C++ person.

-Stanley
 
Hm, I used GetAsyncKeyState API - it can handle mouse and keyboard clicks.
To sum it up, you can also track mouse moving, or use GetForegroundWindow
API to know which application is interacting with user.
 
Back
Top