I am trying to implement a script that register at every second the active window name/process and save to a txt file counting the total time in which the window was active. So far it works. However, I wanted the script to be smart enough to stop when the user lock the screen... any ideas about how to do it?
Any help is appreciated. The code so far is this:
Code: Select all
path=some_random_path
Loop {
ActiveBegin := A_TickCount
WinGetActiveTitle, ActiveTitle
WinGet, ActiveProcess, ProcessName, A
; Wait for some other window to be activated.
WinWaitNotActive, % "ahk_id " . WinActive("A")
; Calculate how long it was active for.
ActiveTime := A_TickCount - ActiveBegin
; Log the title and duration of the active window.
FileAppend, %A_YYYY%-%A_MM%-%A_DD% %A_Hour%:%A_Min%:%A_Sec%$%ActiveTitle%$%ActiveProcess%$%ActiveTime%`n, %path%\log_%A_UserName%.txt
sleep, 1000
}