ms-accessvbawinapiidle-processing

How to get the idle time in Windows XP using VBA?


I would like to know the current idle time from user input on a given Windows XP machine programmatically. I am using VBA in MS Access. What options do I have?


Solution

  • I used the following to obtain the solution.

    Private Declare Function GetTickCount Lib "kernel32" () As Long
    Private Declare Function GetLastInputInfo Lib "user32" (plii As Any) As Long
    
    Private Type LastInputInformation
    
        cbSize As Long
    
        dwTime As Long
    
    End Type
    
    Public Function GetUsersIdleTime() As Long
    
        Dim lii As LastInputInformation
    
        lii.cbSize = Len(lii)
    
        Call GetLastInputInfo(lii)
    
        GetUsersIdleTime = FormatNumber((GetTickCount() - lii.dwTime) / 1000, 2)
    
    End Function
    

    There are other parts of the system which can be idle such as,

    To find out more regarding performance and other idle types see this SO post here.