Lee W, MVP
asked on
VB6 Get Idle Time of system
I'm trying to determine the idle time of the system. I was trying to use this code:
But it's not working. When I put the variables in a text box to see what's going on, I'm getting numbers in the billions for both with the LastInputInfo.Time about 15-16 (varying) less than the GetTickCount value. If I'm reading this, LastInputInfo.Time should be static UNLESS I'm using things... but it's always sensing activity and I'm not sure why...
I'm using a timer control to check every 100 ms - IdleTime is requested every timer cycle.
I'm open to other methods if anyone has them to detect idle time...
Private Type LastInputInfoType
Size As Long 'Bytes
Time As Long 'Dword
End Type
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Function GetLastInputInfo Lib "user32" (plii As Any) As Long
Public Function IdleTime() As Long
Dim LastInputInfo As LastInputInfoType
LastInputInfo.Size = Len(LastInputInfo)
GetLastInputInfo LastInputInfo
IdleTime = GetTickCount - LastInputInfo.Time / 1000
MainForm.Debug1Text = GetTickCount
MainForm.Debug2Text = IdleTime
MainForm.DebugText = "Time: " & LastInputInfo.Time & vbCrLf & "Size: " & LastInputInfo.Size
End Function
But it's not working. When I put the variables in a text box to see what's going on, I'm getting numbers in the billions for both with the LastInputInfo.Time about 15-16 (varying) less than the GetTickCount value. If I'm reading this, LastInputInfo.Time should be static UNLESS I'm using things... but it's always sensing activity and I'm not sure why...
I'm using a timer control to check every 100 ms - IdleTime is requested every timer cycle.
I'm open to other methods if anyone has them to detect idle time...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You’re welcome and I’m glad I was able to help.
If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.
Marty - Microsoft MVP 2009 to 2017
Experts Exchange Most Valuable Expert (MVE) 2015, 2017
Experts Exchange Top Expert Visual Basic Classic 2012 to 2018
Experts Exchange Top Expert VBA 2018
If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.
Marty - Microsoft MVP 2009 to 2017
Experts Exchange Most Valuable Expert (MVE) 2015, 2017
Experts Exchange Top Expert Visual Basic Classic 2012 to 2018
Experts Exchange Top Expert VBA 2018
ASKER
Thanks for the assist!
-Lee