?
Solved

Detecting Idle Time in Delphi

Posted on 2012-03-29
8
Medium Priority
?
1,020 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 23

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 23

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
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.

 

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 23

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 23

Accepted Solution

by:
Ferruccio Accalai earned 2000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month12 days, 5 hours left to enroll

752 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