Page 1 of 1

Putting a settimer to turn off loop

Posted: 11 Mar 2024, 10:38
by ishida20
So I have this code where it loops F1>Click>F2 and has the 5:: function to have it turned off and on
Can anyone help with putting a settimer or any command that when I press 5 to start the command, it'll start looping and after a set time it will press END>F9 and then turn off the loop?
I tried fiddling with the source code and ultimately cannot achieve this. Any help would be appreciated.

Code: Select all

#MaxThreadsPerHotkey 3
5::
#MaxThreadsPerHotkey 1
if KeepWinZRunning
{
KeepWinZRunning := false
return
}
KeepWinZRunning := true
Loop
{
Send {F1}
Sleep 0
MouseClick, Left
Send {F2}
Sleep 100
if not KeepWinZRunning
break
}
return
ESC::ExitApp
[Mod edit: Added [code][/code] tags. Please use them yourself when posting code!]
[Mod edit: Moved topic from AHK v2 help to v1 help, based on posted code.]

Re: Putting a settimer to turn off loop  Topic is solved

Posted: 11 Mar 2024, 11:37
by mikeyww
Welcome to this AutoHotkey forum!

Code: Select all

#Requires AutoHotkey v1.1.33.11
#MaxThreadsPerHotkey 2

5::
KeepWinZRunning := !KeepWinZRunning
SoundBeep 1000 + 500 * KeepWinZRunning
end := A_TickCount + 2000
While KeepWinZRunning && A_TickCount <= end {
 Send {F1}
 If KeepWinZRunning
  Send {LButton}{F2}
 If KeepWinZRunning
  Sleep 100
}
If (A_TickCount > end)
 SoundBeep 1000
KeepWinZRunning := False
Return

Re: Putting a settimer to turn off loop

Posted: 11 Mar 2024, 16:43
by ishida20
That is mint! Working like a charm, and with the added beep if I may add. Thank you so much mikeyww, much appreciated!