如何将热键绑定放置在自动执行脚本的开头/顶部,而不是末尾



通常;加载脚本后,[AutoHotKey]开始在最上面一行执行,直到遇到Return、Exit、热键/热字符串标签或脚本的物理结束(以先到者为准(">

然而,我想把我的热键触发器放在自动执行部分的上方,以便于阅读和/或让最终用户更容易根据自己的喜好编辑热键。我该怎么做?

它非常简单。只需给您的"自动执行"部分一个标签,并在第一个热键绑定之前使用goto命令跳过对这些热键的解析,将其作为自动执行的一部分。

示例:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
UserVariableOne := 3.14
UserVariableTwo := true
UserVariableThree := "Banana"
goto BeginTheScript
^Space::
Msgbox, I am a Hotkeyed Messagebox! %UserVariableOne%
return
+Space::
Msgbox, I am another Hotkeyed Messagebox! %UserVariableTwo%
return
Esc::Exitapp
BeginTheScript:
Msgbox, I am an Auto-execute Messagebox! %UserVariableThree%
return

或者,您只需要在脚本的开头放一个return语句

举个例子:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
UserVariableOne := 3.14
UserVariableTwo := true
UserVariableThree := "Banana"
return ; <---This line here<<
^Space::
Msgbox, I am a Hotkeyed Messagebox! %UserVariableOne%
return
+Space::
Msgbox, I am another Hotkeyed Messagebox! %UserVariableTwo%
return
Esc::Exitapp

最新更新