This is how I implemented this functionality several years ago. The fnIdleTime function will tell you how many seconds have passed since the user touched the mouse or keyboard.
Public Declare Function timeGetTime Lib "WINMM.DLL" () As Long
Private Type LASTINPUTINFO
cbSize As Long
dwTime As Long
End Type
Public Declare Function GetLastInputInfo Lib "user32.dll" (plii As LASTINPUTINFO) As Long
Public Function fnIdleTime() As Long
Dim lii As LASTINPUTINFO
lii.cbSize = Len(lii)
If (GetLastInputInfo(lii) > 0) Then
fnIdleTime = (timeGetTime - lii.dwTime) \ 1000
End If
End Function
raven source
share