Skip to content

Instantly share code, notes, and snippets.

@katchy3132
Last active August 3, 2023 13:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katchy3132/6e7462225a6fe05484c2ab8bafc45f3a to your computer and use it in GitHub Desktop.
Save katchy3132/6e7462225a6fe05484c2ab8bafc45f3a to your computer and use it in GitHub Desktop.
Idle Monitor - Autohotkey- monitor and log idle time
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
LogFileLoc := A_Desktop . "\idlemonitor-log.txt"
LogFileIntervalSec := 10
LogFileIdleGreaterThan := 30
FormatTime, TimeString, d M yyy mm:hh tt
FileAppend , `r`n%TimeString% -Start-----------------`r`n , %LogFileLoc%
; +MinSize300x100
Gui, +SysMenu +Resize +MinimizeBox +Owner ; avoids a taskbar button.
Gui, Add, Text,, Log location : %LogFileLoc%
Gui, Add, Text,, Log interval sec: %LogFileIntervalSec% and idle > %LogFileIdleGreaterThan%
;Gui Add, Text,, Ctrl- c to exit
gui, font, s14, Verdana
Gui, Add, Text, vTimerText w250
Gui, Show, AutoSize, Idle Monitor
StartTime := A_TickCount
Loop
{
IdleTime := FormatMilliSeconds(A_TimeIdle )
FormatTime, TimeString, d M yyy mm:hh tt ; NOW
ElapsedTime := A_TickCount - StartTime
if ( A_TimeIdle >= ( LogFileIdleGreaterThan * 1000 ) && ElapsedTime >= LogFileIntervalSec * 1000 ) {
LogLine := Format("{1}, {2}`r`n", TimeString, IdleTime )
FileAppend , %LogLine% , %LogFileLoc%
StartTime := A_TickCount
}
;Iteration %A_Index%
GuiControl,Text, TimerText, Idle %IdleTime%
;Gui, Show, AutoSize, %IdleTime% - Idle Monitor
Sleep, 1000
}
GuiClose:
ExitApp
;GuiEscape:
;ExitApp
#IfWinActive Idle Monitor ahk_class AutoHotkeyGUI
^c::
ExitApp
#IfWinActive
FormatMilliSeconds(NumberOfMilliSeconds)
{
;MsgBox %NumberOfMilliSeconds%
totalsecs := Round(NumberOfMilliSeconds / 1000)
mins := totalsecs / 60
secs := Mod(totalsecs, 60 )
return Format("{1:01d}:{2:02} [{3}]", mins, secs, NumberOfMilliSeconds)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment