对于复合if语句,AutoHotkey在相同的花括号上窒息

时间:2009-12-01 19:07:47

标签: compiler-errors autohotkey curly-braces

我遇到一个问题,AutoHotkey告诉我在'else'前面缺少{,我觉得我的代码完全正常。 (直到我将与窗口相关的if从Pidgin更改为qutIM之后才开始工作)

^!p::
   IfWinExist ahk_class QWidget, ,qutIM {  ;if there is a qutIM-window other than the buddy-list...
      IfWinNotActive ahk_class QWidget, , qutIM {  ;ans it is not active...
         WinActivate
      } else {  ;the closing bracket in front of the else here puts AHK off...
         WinMinimize
      } 
   } else {  ;do some stuff with the buddy-list
      ; [...]
   } 
return

我担心我会忽略一些愚蠢的东西,但我似乎无法让它发挥作用。

3 个答案:

答案 0 :(得分:2)

如果我没弄错的话,One True Brace风格只能用于纯粹的If语句,而不能用于像IfWinExist这样的化合物。

From the documentation for if-expressions

  

One True Brace(OTB)样式可以选择使用   if语句是表达式(但不是传统的   if语句)。

IE中。你必须使用WinExist()形式,而不是IfWinExist。

答案 1 :(得分:-1)

As PhiLho stated,The One True Brace(OTB)样式不能与复合if语句一起使用。

虽然WinNotActive()没有直接功能,但您可以使用!作为相同效果的修饰符。

^!p::
   if WinExist("ahk_class QWidget", , "qutIM") {
      if !WinActive("ahk_class QWidget", , "qutIM") {
         WinActivate
      } else {
         WinMinimize
      } 
   } else {
      ; [...]
   } 
return

答案 2 :(得分:-2)

由于我没有你正在测试它的应用程序,我不确定你要做什么,但这可能是另一种方式:

^!p::
IfWinExist, ahk_class Notepad ; if there is a qutIM-window other than the buddy-list
    {
    WinActivate
    Exists=True
    }
else ;the closing bracket in front of the else here puts AHK off...
    {
    WinMinimize
    Exists=False
    }
If Exists=True 
    MsgBox, do some stuff with the buddy-list ; dummy code
Else
    {
    Msgbox, Exiting App ; dummy code
    ExitApp
    }