Hi, my small brother claims he is not playing computer games during the time of the day he promised my parents he would do homework. I want to make a script that counts the exact amount of minutes a window has been open and keep a log (which is easy to do) but I want it to count only time within a specific time. What I mean is that I want it to count it only if the window is open within lets say 16:00 to 18:00. If the window is opened at 19:30 it wound not count. But if it would be opened at 15:45 and kept open until 18:20, the script would count and log 20 min (only from 18:00) rather than 35.
I guess I could do with a timer or loop and a series of "if A_Hour > 18" and so on, but isnt there a more accurate or less rudimental way?
Thank you!
Homework monitor
Re: Homework monitor
Here are some ideas for logging, though needs some adjustments & times added.
Code: Select all
; #NoTrayIcon
DllCall("RegisterShellHookWindow", "UInt", A_ScriptHwnd)
OnMessage(DllCall("RegisterWindowMessage", "Str", "SHELLHOOK"), "window")
Return
window(wParam, lParam) { ; Action, HWND
Static games := "notepad,EXCEL", prog := {}
Switch wParam {
Case 1: ; Window was created
If (A_Hour A_Min > 1800)
Return
WinGet, pname, ProcessName, ahk_id %lParam%
SplitPath, pname,,,, fnBare
If fnBare in %games%
prog[lParam, "name"] := fnBare, prog[lParam, "start"] := A_Now, log(prog[lParam], "Opened")
Case 2: ; Window was destroyed
If prog.HasKey(lParam)
log(prog[lParam], "Closed"), prog.Delete(lParam)
}
}
log(program, openClose) {
Static logFile := A_ScriptDir "\games.log"
FormatTime, time, % now := A_Now, yyyy/MM/dd,HH:mm
pname := program.name
If (openClose = "Closed") {
elapsed := now
elapsed -= program.start, S ; Elapsed time in seconds
elapsed := "," elapsed
}
FileAppend, %time%`,%pname%`,%openClose%%elapsed%`n, %logFile%
}
Re: Homework monitor
I think this would do, looks amazing! Thank you!!!!!!!!!