Pages

Sunday, December 25, 2011

How to get idle time in delphi

Sometimes when we create a program, we want to know whether user doing some activity or not. For security reason we want to auto log off that user from application if his idle time over limit that we have been set.
Below is the function to get idle time of user :
function SecondsIdle: DWord;
var
   liInfo: TLastInputInfo;
begin
   liInfo.cbSize := SizeOf(TLastInputInfo) ;
   GetLastInputInfo(liInfo) ;
   Result := (GetTickCount - liInfo.dwTime) DIV 1000;
end;
 
To use that function we can do as below :
procedure TForm1.Timer1Timer(Sender: TObject) ;
begin
   showmessage(Format('You are idle in %d seconds', [SecondsIdle]));
end;

No comments:

Post a Comment

Don't Forget To Join Our Community
×
Widget