I need to get the system idle time when an event is triggered in my application. I used the GetLastInputInfo() function to get it, but it seems that after 5 minutes and a few seconds of inactivity, my idle counter is restarted back to zero, without me touching the mouse or keyboard. My screensaver is deactivated, and also all of the standby and sleep settings of the system and display!
What can be the cause?
I used this code to test the problem:
procedure TMsgForm.Timer1Timer(Sender: TObject);
var mins, secs, T0, T1, TD: Cardinal;
LastInput: TLastInputInfo;
begin
LastInput.cbSize:=SizeOf(TLastInputInfo);
if not GetLastInputInfo(LastInput) then Caption := 'error'
else begin
T0 := GetTickCount;
T1 := LastInput.dwTime;
TD := T0 - T1;
secs := TD div 1000;
mins := secs div 60;
Caption := 'T0='+IntToStr(T0)+' T1='+IntToStr(T1)+' TD='+IntToStr(TD)+' secs='+IntToStr(secs)+' mins='+IntToStr(mins);
end;
end;
UPDATE:
I closed all programs and then waited again 5 minutes, and the same thing happens. I thought that some program I installed may be simulating a user input or something, and so resets the idle counter. But it doesn't. There must be something from the system that does it?
I also tried on another computer and it works fine. It is not reset after 5 minutes.
UPDATE
It is strange... hooking the keyboard and mouse, I don't receive anything at the moment the standard idle counter is reset. So, the only logical conclusion is that the counter is restarted from other sources.
I managed to get the real idle time by installing keyboard and mouse hooks, which has a flag that tells if the source of the trigger was real or not. It works, but its not a nice implementation. I can't believe that Microsoft hasn't thought about implementing a system idle timer for REAL events, like
GetLastInputInfo(LastInput).I don't know if there are other inputs sources other then keyboard and mouse... If anyone can help me improve this procedure, it is welcome.