Solved

Detecting Idle Time in Delphi

Posted on 2012-03-29
8
971 Views
Last Modified: 2012-03-29
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
Comment
Question by:ChrisJonesLycos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 37782571
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
 

Author Comment

by:ChrisJonesLycos
ID: 37782607
The MSDN documentation says that that's for your own window only, not system wide.
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 37782626
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ChrisJonesLycos
ID: 37782640
Is that not the same? I'll try out some code and see what result I get.
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 37782662
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
 

Author Comment

by:ChrisJonesLycos
ID: 37782700
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
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 500 total points
ID: 37782701
@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
 

Author Closing Comment

by:ChrisJonesLycos
ID: 37782732
I accepted your solution. Not sure what happened.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question