Getlastinputinfo is the detection system input, applied to a program is not appropriate!
There are two ways to monitor input messages for this problem:
1. Thread-level hooks, hook up mousehook and Keyboardhook
2. Do the processing in Application.onmessage
Obviously, the 2nd method is more convenient!
As we all know, the keyboard and mouse messages are queue messages, need to pass through the message queue after some processing, and then sent to the various wndproc. Based on this principle, we can do the message processing in the OnMessage, that is, declare the global variables, to save the last input action time, and then use the time control to do a timed scan, with GetTickCount to determine whether to timeout.
UnitUnit1;InterfaceusesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Appevnts, Extctrls, stdctrls;
typeTForm1=class(tform) applicationevents1:tapplicationevents; Tmr1:ttimer; Edt1:tedit; procedureApplicationevents1message (varmsg:tagmsg; varHandled:boolean); procedureTmr1timer (Sender:tobject); Private {Private Declarations} Public {Public Declarations} End;varForm1:tform1; Elapsedtime:longint;Implementation{$R *.DFM}procedureTform1.applicationevents1message (varmsg:tagmsg; varHandled:boolean);begin CaseMSG.message ofWm_keydown,wm_lbuttondown,wm_lbuttonup://various keyboard and mouse messages beginElapsedTime:=GetTickCount; //handled:=true; Do not set Handled to True here, otherwise the message will not be distributed to WndProc. End; End;End;procedureTform1.tmr1timer (sender:tobject);begin ifGettickcount-elapsedtime>60000 Then beginTMR1. Enabled:=false; ShowMessage ('1 minutes, the software's not working.'); End;End;End.
Reference: http://www.cnblogs.com/key-ok/p/3358918.html
Determine the idle time of the software (use Application.onmessage to filter all keyboard and mouse messages)