Hi,
I want to know if its possible to auto-run a macro if there was no mouse or keyboard event for say 2mins. I have a code working to record system idle time in total but that gives me endless counts by end of the day as it records every 2 mins.once user logs in to the form.
I instead want to trigger the macro only when user is not using keyborad or mouse for more than 2 mins.
Below code: Paste it in a module, Open the immediate window and run printidletime1. Every 2 mins you would see time stamps in "sheet1".
Private Type LASTINPUTINFO
cbSize As Long
dwTime As Long
End Type
Private Declare Sub GetLastInputInfo Lib "user32" (ByRef plii As LASTINPUTINFO)
Private Declare Function GetTickCount Lib "kernel32" () As Long
Function IdleTime() As Single
Dim a As LASTINPUTINFO
a.cbSize = LenB(a)
GetLastInputInfo a
IdleTime = (GetTickCount - a.dwTime) / 1000
End Function
Sub PrintIdleTime1()
Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1) = IdleTimeApplication.OnTime Now + TimeSerial(0, 2, 0), "PrintIdleTime2"
End Sub
Bookmarks