这不是你可以轻易做到的事情。
您可以执行以下操作:https://stackoverflow.com/questions/12851677/dynamically-create-autohotkey-hotkey-to-function-subroutine
或者您可以在运行时修改文件并重新加载它。
#SingleInstance Force
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
^!n::
WinGet, pn, ProcessName, A
path := GetProcessPath(pn)
tooltip, press a new hotkey
Input, new_hotkey, L1
tooltip,
code = ^!%new_hotkey%`:`:Run, %path%`n
FileAppend, %code%, %A_ScriptFullPath%
Reload
Sleep 1000 ; If successful, the reload will close this instance during the Sleep, so the line below will never be reached.
MsgBox, 4,, The script could not be reloaded. Would you like to open it for editing?
IfMsgBox, Yes, Edit
return
GetProcessPath(exe) {
;;http://www.autohotkey.com/board/topic/32965-getting-file-path-of-a-running-process/
for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process where name ='" exe "'")
return process.ExecutablePath
}
return
Hotkeys:
^!f::Run, C:\Program Files\Mozilla Firefox\firefox.exe