如何编写创建热键的脚本?

How to write a script that creates hotkeys?

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

; 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")

然而,这只是打开一个命令window。我究竟做错了什么?有没有 easier/better 方法来完成这个?

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

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

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