如何在自动热键中创建while循环,该循环在按{Ctrl}时会中断? [英] How do I create while loop in autohotkey that breaks when I press {Ctrl}?

查看:105
本文介绍了如何在自动热键中创建while循环,该循环在按{Ctrl}时会中断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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++
    }
}

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

I want the ability to stop the loop by pressing {Ctrl}. What's the best way to accomplish my goal?

推荐答案

尝试一下:

F1:: foo()

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

这篇关于如何在自动热键中创建while循环,该循环在按{Ctrl}时会中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆