繁体   English   中英

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

[英]How can I place Hotkey bindings at the start/top of an autoexecuting script rather than the end?

通常,“脚本加载后,[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

来源

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM