是否有等同于 'if WinNotExist()' 的功能?

Is there a functional equivalent to 'if WinNotExist()'?

AutoHotkey 语法的一个限制是缺少 not 用于纯 if 语句的修饰符。

IfWinExist, Untitled - Notepad       ; valid
IfWinNotExist, Untitled Notepad      ; valid
If WinExist("Untitled - Notepad")    ; valid
If WinNotExist("Untitled - Notepad") ; invalid

虽然这通常不是问题,但在坚持 Egyptian Brackets/One True Brace (OTB) 风格时可能会变得麻烦。

The One True Brace (OTB) style may optionally be used with if-statements that are expressions (but not traditional if-statements).
- AHK documentation on if-statements

这两个问题的结合使我无法进行简单的错误检查来验证 window 是否存在。

IfWinNotExist, Untitled - Notepad {  
    Return   ; invalid
}

If WinNotExist("Untitled - Notepad") {
    Return   ; invalid
}

我找到的唯一解决方案是要么打破 OTB 风格并将括号放在换行符上,要么使用不必要的冗余 if-else 语句。

如何使用函数检查 AutoHotkey 中是否不存在 window?

事实证明有一个简单的解决方案:使用 ! 作为 not 修饰符。

If !WinExist("Untitled - Notepad") {
    Return
}

:

If not WinExist("Untitled - Notepad") {
    Return
}