Autohotkey ELSE 语句不起作用。有替代品吗?

Autohotkey ELSE statements not working. Any replacement?

我正在制作自动热键脚本。

问题是 ELSE 命令有时不起作用。

如何解决这个问题?

改用 IF 命令。

例如:

<^<!-::
If GetKeyState ("u", "p")
MsgBox hey!
If not GetKeyState ("u", "p")
MsgBox bye!

希望对您有所帮助。

当您在 AHK v1 中编码时,最常见的混淆来源之一是已弃用的传统 if 语句与使用表达式的更合理的现代 if 语句之间的区别。

official documentation 说:

An If statement that contains an expression is usually differentiated from a traditional If statement such as if FoundColor != Blue by enclosing the expression in parentheses, ...

你的情况是,当 AHK 将它们解释为已弃用的语句时,你打算使用现代的、通用的 if 语句,这就是你的 else 没有被识别的原因。

括号并不是每次都需要,但在您掌握它之前,请确保您使用它们:

if (expression)
  DoThis
else
  OrThat