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

问题描述 投票:1回答:2

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

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

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

autohotkey
2个回答
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++
    }
}

0
投票
~Ctrl::counter := 10
F1:: foo()

foo(){
    global counter:=1
    while(counter<10)
    {    
    send, %counter%
    Random, SleepAmount, 2300, 3300
    sleep, SleepAmount
    counter++
    }
}
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.