Link to home
Start Free TrialLog in
Avatar of Bryan_123
Bryan_123

asked on

Determining system idle time using GetLastInputInfo and LastInputInfo

Is there a way in FoxPro that I can read the system idle time. I have a timer on the main form that is set up for 15 second intervals and I'd like it to check how long the computer has been idle. I don't want to record my own keystokes and mouse clicks. I just want to read the system settings. I'm having trouble with the GetLastInputInfo and LastInputInfo API calls.
ASKER CERTIFIED SOLUTION
Avatar of Cyril Joudieh
Cyril Joudieh
Flag of Lebanon image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bryan_123
Bryan_123

ASKER

I'm trying this:

Declare Integer GetTickCount In kernel32
Declare Short GetLastInputInfo In win32API String @ plii

iTime      = GetTickCount()
plii      = Chr(8) + Replicate(Chr(0), 7)
iLast      = GetLastInputInfo(@plii)

iLast ends up being an 8 character string instead of a number.

In VB.Net GetTickCount() gave me the in milliseconds how long my computer has been on (It does this in FoxPro). Then GetLastInputInfo would get me the number of milliseconds that my computer had been on when the last keypress or mousemove had been made. I then just subtracted the GetLastInputInfo from the GetTickCount and divided the result by 60000 to get how long in minutes the computer had been idle. But in foxpro, I can't use the GetLastInputInfo the same way because of the syntax. I'm stuck. I don't know how to translate the 8 character that GetLastInputInfo returns.
Thank you for pointing me in the right direction!
Here's how I got it to work

Local iTime As Integer, iLast As Integer
Local plii As String, cLast As String

Declare Integer GetTickCount In kernel32
Declare Short GetLastInputInfo In win32API String @ plii

iTime      = GetTickCount()
plii      = Chr(8) + Replicate(Chr(0), 7)
cLast      = GetLastInputInfo(@plii)
iLast      = (Asc(Substr(plii, 8, 1)) * 16777216) + ;
(Asc(Substr(plii, 7, 1)) * 65536) + ;
(Asc(Substr(plii, 6, 1)) * 256) + ;
Asc(Substr(plii, 5, 1))

iTime is the milliseconds your computer has been on.
iLast is the milliseconds your computer was on when your last keystroke or mousemove was.

To get minutes idle:
(m.iTime - m.iLast) / 60000