运行 命令在 autohotkeys n 次

run command in autohotkeys n number of time

我想在自动热键中执行我的命令 运行s 特定次数 (n)。 示例:

::t::
    send test
return 

现在您键入 t 并按 tab 它会打印 test。我想指定数字(例如 5)。因此命令将键入 testtesttesttest(测试 5 次)。伪代码是这样的:

::t::n
    send test
return 

n 是命令应该 运行 的次数。我对 autohotkeys 很陌生,我需要这么快,但无法通过谷歌搜索找到信息。谢谢。

::t::
    input, count, I T5, {Enter}
    if count is Integer
    {
        loop, %count%
            send test
    }
return

在按下 tTab 后,您将有 5 秒的时间输入任何数字(按下 [=45= 接受]输入,按退格键删除数字,然后立即发送test次。

另请参阅:loop, input

编辑:如果您已经知道要发送 test 的频率,您可以简单地选择

::t::
     loop, 10
            send test
return

OK it works, but can you make that I type t5 and then tab, or t7, t15, t45, etc... And it runs command 5 times(or n times). So I end with pressing tab

嗯,这是不同的东西。您正在尝试实现 hotstring with out of a variable part. There is no such thing as regular expression hotstrings (::t[0-9]*::). Let's build it ourselves then, using a simple hotkey~t:: 而不是 ::t::)。

如果你不介意t的自然函数被覆盖,你可以使用

t::
    input, count, I T5, {Tab}
    if count is Integer
    {
        loop, %count%
            send test
    }
return

同上,只是tab只在数字后面。热键 (t::) 不需要任何额外的触发键。

另一方面,如果你想在正常情况下也使用 t,但你想要 t5Tab转换成testtesttesttesttest,可以使用类似下面的方式:

~t::
    input, count, I T5 V, {Tab} ; V: input will be visible because if not used as t3{tab}, we want to keep the written input
    if count is Integer
    {   ; if not, than user probably just used t in a normal string context
        ifInString, ErrorLevel, EndKey  ; if input was terminated by {tab}
            send {BS}   ; = {Backspace}
        else {
            return ; you can delete this line. Keep it, if you want t3 to be transformed into testtesttest only after the timeout ran out, even without TAB being pressed.
        }
        send {BS}   ; remove the t
        loop, % strLen(count)
            send {BS}   ; remove the numbers
        loop, % count
            send test
    }
return

^ 这基本上是一个变量热字串。


一个更漂亮的方法可能是:

::t1::send test
::t2::
    loop, 2
         send test
return
::t3::
    loop, 3
         send test
return

等等。但这显然很难实现。