Author: Tomas Rutkauskas
Is there a way to find out when the user last clicked on a program's interface? It
is some sort of like idle time but the idle time for this specific program.
From inside the application it is fairly easy. You need three pieces of equipment
A "Time of last activity" variable, field of your main form
1 2 FLastActive: TDateTime;
A timer that regularly checks the FLastActive variable against the current time.
Set it to an interval of, say 60000, and set its Active property to true at
design-time. The OnTimer event handler would be something like this (timeout after
3 if (FLastActive + EncodeTime(0, 15, 0, 0)) < Now then4 Close;
A handler for the Application.OnMessage event that updates the FLastActive variable
on each key or mouse message. The handler would do something like this:
5 case msg.messageof6 WM_KEYFIRST..WM_KEYLAST, WM_MOUSEFIRST..WM_MOUSELAST:
7 FLastActive := Now;