Just an idea I cooked up on the fly last night after looking for a torrent program that would run as a screen saver, the purpose of that being to always be seeding when the system is idle. Composed largely of snippets obtained from these very forums!
Code:
Loop1:
;for when UT isn't running - wait for the system to go 15 minutes idle, then fire it up
Loop {
Sleep, 10000
if (A_TimeIdlePhysical > (15*60*1000))
goto RunUT
}
Loop2:
;for when UT has been started - watch for activity to prompt user to kill it
Loop {
Sleep, 10000
if (A_TimeIdlePhysical < 11000)
goto KillUT
}
Loop3:
;for when UT closure has been canceled by the user - wait for the system to go idle again and kick into loop1
Loop {
Sleep, 10000
if (A_TimeIdlePhysical > (15*60*1000))
goto Loop1
}
RunUT:
Run, "C:\Program Files\uTorrent\uTorrent.exe"
Goto Loop2
Return
KillUT:
Gui, Add, Text, x2 y2 w240 h20 , Good morning! Do you want to exit uTorrent now?
Gui, Add, Button, x12 y32 w90 h30 Default gYes, &Yes!
Gui, Add, Button, x122 y32 w90 h30 gNo, &No!
Gui, Show, x484 y224 h74 w244, IMPORTANT QUESTION
Return
GuiClose:
goto No
Yes:
Gui, Submit
DetectHiddenWindows, On
Process, Exist, utorrent.exe
WinGet, W, List, ahk_pid %ErrorLevel%
Loop %W%
{
WinGetClass, Class, % "ahk_id" W%A_Index%
If InStr( Class, "µTorrent" ) {
hWnd := W%A_Index%
Break
}}
MouseGetPos, X, Y
MouseMove, A_ScreenWidth, A_ScreenHeight, 0
PostMessage, 0x8001, 0,0x204,, ahk_id %hWnd% ; Right Click down
PostMessage, 0x8001, 0,0x205,, ahk_id %hWnd% ; Right Click Up
ControlSend,,{Up 1}{Enter},ahk_id %hWnd%
MouseMove, X, Y, 0
goto Loop1
No:
Gui, Submit
goto Loop3
;following hotkeys for testing purposes, feel free to snip out
#U::
goto KillUT
#T::
goto RunUT
Optimizations and comments welcome, I know it's very rough.