Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1184
  • Last Modified:

Detecting Idle Time in Delphi

I have an app that needs to detect when the whole system has not received any input from keyboard or mouse for a few minutes. I've found some very complicated hooking examples online which involve DLLs and some others that simply don't work. Can anyone suggest a straight forward way of doing this.
0
ChrisJonesLycos
Asked:
ChrisJonesLycos
  • 4
  • 4
1 Solution
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
what about using GetLastInputInfo?
edit: you need it systemwide, so this function can't help you :(

function SecondsIdle: DWord;
var
  liInfo: TLastInputInfo;
begin
  liInfo.cbSize := SizeOf(TLastInputInfo);
  GetLastInputInfo(liInfo);
  Result := (GetTickCount - liInfo.dwTime) DIV 1000;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Caption := Format('System IDLE last %d seconds', [SecondsIdle]);
end;

Open in new window

0
 
ChrisJonesLycosAuthor Commented:
The MSDN documentation says that that's for your own window only, not system wide.
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
No wait, it says literaly "GetLastInputInfo does not provide system-wide user input information across all running sessions. Rather, GetLastInputInfo provides session-specific user input information for only the session that invoked the function"
It speaks about sessions, not "window"
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
ChrisJonesLycosAuthor Commented:
Is that not the same? I'll try out some code and see what result I get.
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
For a session I mean a User session. If you have some user remotely connected that's a separate session I guess. It's like it works into HKCU instead of HKLM
Anyway, everywhere I read, the suggested approach for a system idle detection is this.
0
 
ChrisJonesLycosAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for ChrisJonesLycos's comment #37782640

for the following reason:

Cool. You're right, code works! Session obviously doesn't mean just your own app, it's definitely system wide. Many thanks.
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
@Cool. You're right, code works! Session obviously doesn't mean just your own app, it's definitely system wide. Many thanks.

So why a Close Request? Don't you think you should accept my comment as answer?
0
 
ChrisJonesLycosAuthor Commented:
I accepted your solution. Not sure what happened.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now