How to detect inactive (idle) user in Windows application? I’d like to shutdown application when there hasn’t been any input (keyboard, mouse) from user for certain period of time.
How to detect inactive (idle) user in Windows application? I’d like to shutdown application
Share
To track a user’s idle time you could hook keyboard and mouse activity. Note, however, that installing a system-wide message hook is a very invasive thing to do and should be avoided if possible, since it will require your hook DLL to be loaded into all processes.
Another solution is to use the
GetLastInputInfoAPI function (if your application is running on Win2000 (and up) machines).GetLastInputInforetrieves the time (in milliseconds) of the last input event (when the last detected user activity has been received, be it from keyboard or mouse).Here’s a simple example. The
SecondsIdlefunction returns a number of second with no user activity (called in anOnTimerevent of aTTimercomponent).http://delphi.about.com/od/adptips2004/a/bltip1104_4.htm