I would like to effectively auto-press the 1 or 2 key, depending on what hotkey I press. I'm currently using ctrl+1 for 1 and ctrl+2 for 2, with ctrl+3 to pause the program, but I'm running into trouble with alternating between the two without it just doing 2 forever. Additionally, I've had times when I get stuck in an infinite loop and none of the hotkeys stop it and I don't know why (I have to reset my computer). It would be ideal to have a failsafe hotkey or a better pause feature!
So if I press Ctrl+1, I want it to go like '111111111' to infinity (or for a maximum of 2 minutes if that's helpful!). I want it to stop when I press something else, whether it's ctrl + 1 again, ctrl+ 3 or any key at all, I don't really mind! The ideal would be for any key at all to interrupt the program but I'm not sure if that's possible.
Same if I press Ctrl+2.
This is the code I found online and just altered the numbers and doubled it.
Code: Select all
#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.
#MaxThreadsPerHotkey, 2
looping = 0
$^2:: ;<-- the hotkey with a $ so it won't re-trigger itself
keywait, 2 ;<-- make sure to let go of the 2 key
looping := !looping ;<-- is the switch to tell the loop to start or stop
if (!looping) ;<-- if the toggle is now off don't do the loop
Return
loop ;<-- an infinite loop with a break condition inside
{ If (!looping) ;<-- the loop will break once the looping flag is flipped off
Break
send, {2 down}
;send {k down}
sleep, 200
}
Send, {2 up}
; send {k up}
$^1:: ;<-- the hotkey with a $ so it won't re-trigger itself
keywait, 1 ;<-- make sure to let go of the 2 key
looping := !looping ;<-- is the switch to tell the loop to start or stop
if (!looping) ;<-- if the toggle is now off don't do the loop
Return
loop ;<-- an infinite loop with a break condition inside
{ If (!looping) ;<-- the loop will break once the looping flag is flipped off
Break
send, {1 down}
;send {k down}
sleep, 200
}
Send, {1 up}
; send {k up}
^3::Pause ;<-- Pauses the script
ExitApp