问题
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?
回答1:
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,
- CPU
- Disk
- Network
- Other devices
To find out more regarding performance and other idle types see this SO post here.
来源:https://stackoverflow.com/questions/2589236/how-to-get-the-idle-time-in-windows-xp-using-vba