Reputation: 1385
I am trying to make a process automatic, until I require it to stop.
I press a button on my keyboard, for example F2.
When F2 pressed, it starts a loop that presses F9 every second or so.
This keeps on going until I press F2 again.
I have watched tutorials but all people ever really cover is the mouseclicks. Also the help/tutorialpages from autohotkey itself are very bombastic. This should be very simple and yet it is not.
F2::
SetTimer TheLoop, 200
Return
TheLoop:
Send {F9}
Return
Anyone that can help me here?
Upvotes: 0
Views: 4035
Reputation:
Try using a variable as a toggle as to whether the timer is run or turned off. Something like:
F2::
bToggle := !bToggle
If bToggle
SetTimer , TheLoop , 200 ; This is 200 ms
Else
SetTimer , TheLoop , Off
Return
TheLoop:
Send , {F9}
Return
Here's a more condensed version using the ternary operator and evaluated expressions:
f2::SetTimer , TheLoop , % (( bToggle := !bToggle ) ? "200" : "Off" )
TheLoop:
Send , {f9}
Return
Upvotes: 3