How do I create while loop in autohotkey that breaks when I press {Ctrl}?

这一生的挚爱 提交于 2019-12-08 06:51:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!