【问题标题】:How to write a script that creates hotkeys?如何编写创建热键的脚本?
【发布时间】:2017-02-04 03:27:49
【问题描述】:

我定义了很多小热键,比如:

; Open CMD
#c::
    Run, cmd.exe
    WinWait, ahk_exe cmd.exe
    WinActivate
Return

我想构建一个带有 exe 和热键的函数,它会将应用程序与该热键绑定。到目前为止,这是我所拥有的:

bind_exe_to_hotkey(exe,hotkey)
{
    run_label:
        Run, %exe%
        WinWait, ahk %exe%
        WinActivate
    Return

    HotKey, %hotkey%, run_label
}

bind_exe_to_hotkey("cmd.exe","#c")

但是,这只会打开一个命令窗口。我究竟做错了什么?有没有更简单/更好的方法来实现这一点?

【问题讨论】:

  • 您的函数只是打开一个命令窗口,因为它在“HotKey”执行之前返回。 “run_label”什么都不做;它只是一个类似 goto 的入口指针。执行 Run、WinWait 和 WinActivate 语句,然后函数在到达 HotKey 语句之前返回。

标签: autohotkey


【解决方案1】:

将键绑定到处理启动可执行文件的函数:

#c: launch("cmd.exe")
#n: launch("notepad.exe")

launch(exe)
{
   Run, %exe%
   WinWait, ahk %exe%
   WinActivate
}

【讨论】:

    猜你喜欢
    • 2011-06-11
    • 1970-01-01
    • 1970-01-01
    • 2019-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-23
    相关资源
    最近更新 更多