tags:

views:

186

answers:

1

I'm attempting to make my own instant messenger and want the user to go into idle/away mode if the computer hasn't been used in so long. Does anyone have a great idea on how to do this?

+3  A: 

Here's how I implemented this functionality a few years ago. Function fnIdleTime will tell you how many seconds it has been 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