'获得鼠标和键盘动作的Api
Private Declare Function GetLastInputInfo Lib "user32" (plii As LASTINPUTINFO) As Boolean
Private Type LASTINPUTINFO
cbSize
As Long
dwTime
As Long
End Type
' 获得当前时间 单位为毫秒
Private Declare Function GetTickCount Lib "kernel32" () As Long
' 控制系统关机的Api
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Const EWX_SHUTDOWN = 1
Const EWX_LOGOFF = 0
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
Dim mEvent
As LASTINPUTINFO
Dim StopTime
As Long
' 鼠标和键盘,开始无动作的时间
Dim PrvEvent
As Long
' 上一次鼠标或者键盘的状态
Private Sub Timer1_Timer()
mEvent.cbSize = Len(mEvent)
GetLastInputInfo mEvent
Debug.Print mEvent.dwTime
' 判断鼠标和键盘的状态,如果状态改变,则重新设置监视时间,保存当前状态
If mEvent.dwTime <> PrvEvent Then
PrvEvent = mEvent.dwTime
StopTime = GetTickCount
Else
If (GetTickCount - StopTime) >= (60 * 100) Then
MsgBox "系统已经有六秒没有动作了", , "提示"
End If
End If
End Sub