问题
I have the following while-loop in autohotkey inside a function:
foo(){
counter:=1
while(counter<10)
{
send, %counter%
Random, SleepAmount, 2300, 3300
sleep, 3000
counter++
}
}
I want the ability to stop the loop by pressing {Ctrl}
. What's the best way to accomplish my goal?
回答1:
Try it this way:
F1:: foo()
foo(){
counter := 1
while(counter < 10)
{
send, %counter%
Random, SleepAmount, 23, 33
loop 100
{
Sleep, %SleepAmount%
If GetKeyState("Ctrl", "P")
return
}
counter++
}
}
回答2:
~Ctrl::counter := 10
F1:: foo()
foo(){
global counter:=1
while(counter<10)
{
send, %counter%
Random, SleepAmount, 2300, 3300
sleep, SleepAmount
counter++
}
}
来源:https://stackoverflow.com/questions/47954567/how-do-i-create-while-loop-in-autohotkey-that-breaks-when-i-press-ctrl