AHK 脚本末尾是否需要 `return` 语句?

Is the `return` statement necessary at the end of an AHK script?

我的一行脚本:

Shift::Send ^{Space}

是否需要像下面这样添加return语句?

Shift::Send ^{Space}

return

如果子例程带有如上所示的标签,子例程将被调用并继续执行,直到到达 return 或退出。

因此在此示例中,return 不是必需的

对于函数,return 实际上是在 ahk 中假定的,因此您不一定需要包含它,除非您使用表达式传递它。

尽管在任何一种情况下,您都可能希望将其包含在内,只是为了让内容更具可读性。

引用 return 文档中的示例来演示它的作用:

The first Return separates the hotkey from the subroutine below. If it were not present, pressing the hotkey would cause Sleep 1000 to be executed twice.

#z::
MsgBox The Win-Z hotkey was pressed.
Gosub MySubroutine
return

MySubroutine:
Sleep 1000
return

另外,引自Hotkeys Introduction and Simple Examples

If a hotkey needs to execute only a single line, that line can be listed to the right of the double-colon. In other words, the return is implicit:

#n::Run Notepad

附带说明,如果将多个热键绑定到同一个动作,我们可以这样写:

#a::
#b::MsgBox