在autohotkeys中运行命令n次

时间:2015-05-18 20:59:40

标签: windows scripting autohotkey

我想让我的命令在autohotkeys中运行特定次数(n)次。 示例:

::t::
    send test
return 

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

::t::n
    send test
return 

n将是命令运行的次数。我是noob to autohotkeys,我需要这么快,并且无法找到信息谷歌搜索。谢谢。

1 个答案:

答案 0 :(得分:1)

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

t Tab 后,这将给你5秒钟输入任意数字(按 Enter 接受,删除数字按 Backspace )并立即发送test次。

另请参阅:loopinput

编辑:如果你已经知道你希望发送test的频率,你可以简单地去找

::t::
     loop, 10
            send test
return
  

确定它有效,但是你能不能输入t5然后选项卡,或t7,t15,t45等...并运行命令5次(或n次)。所以我以按Tab键结束

嗯,那是不同的。你试图用可变部分来实现hotstring。没有正则表达式hotstrings(::t[0-9]*::)这样的东西。让我们自己构建它,使用简单的hotkey~t::代替::t::)。

如果您可以覆盖 t 的自然功能,可以使用

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

与上面相同,但标签仅在数字后面。热键(t::)不需要任何额外的触发键。

另一方面,如果你想在正常的上下文中使用 t ,但你想要 t 5 Tab 转换为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

^这基本上是一个变量hotstring。

更美妙的方法可能是:

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

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