当我按下{Ctrl}时,如何在autohotkey中创建while循环?

时间:2017-12-23 17:35:50

标签: autohotkey

我在函数中的autohotkey中有以下while循环:

foo(){
    counter:=1
    while(counter<10)
    {    
    send, %counter%
    Random, SleepAmount, 2300, 3300
    sleep, 3000
    counter++
    }
}

我希望能够通过按{Ctrl}来停止循环。什么是实现目标的最佳方式?

2 个答案:

答案 0 :(得分:1)

以这种方式尝试:

F1:: foo()

foo(){
    counter := 1
    while(counter < 10)
    { 
        send, %counter%
        Random, SleepAmount, 23, 33     
        loop 100
        {
            Sleep, %SleepAmount%
            If GetKeyState("Ctrl", "P") 
                return
        }
        counter++
    }
}

答案 1 :(得分:0)

~Ctrl::counter := 10
F1:: foo()

foo(){
    global counter:=1
    while(counter<10)
    {    
    send, %counter%
    Random, SleepAmount, 2300, 3300
    sleep, SleepAmount
    counter++
    }
}
相关问题