【问题标题】:AutoHotkey choking on same-line curly brace for compound if statementsAutoHotkey 在复合 if 语句的同一行花括号上窒息
【发布时间】:2009-12-01 19:07:46
【问题描述】:

我有一个问题,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

我担心我忽略了一些愚蠢的事情,但我似乎无法让它发挥作用。

【问题讨论】:

    标签: compiler-errors autohotkey curly-braces


    【解决方案1】:

    如果我没记错的话,One True Brace 样式只能用于纯 If 语句,不能用于 IfWinExist 之类的复合词。

    From the documentation for if-expressions:

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

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

    【讨论】:

    • 非常感谢,这就是我的问题的解决方案(但我仍然想知道为什么它在那之前起作用了 o.O)
    • @StevenVascellaro 显然,您回答了自己的问题,这是一件好事... :-)
    【解决方案2】:

    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
    

    【讨论】:

      【解决方案3】:

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

      ^!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
          }
      

      【讨论】:

      • 这是关于打开/隐藏多窗口 IM 客户端的聊天窗口...正如 PhiLho 指出的那样,我只是为我的 if 使用了错误的符号,但还是谢谢你;)
      猜你喜欢
      • 2017-06-14
      • 1970-01-01
      • 2012-05-03
      • 2023-01-16
      • 1970-01-01
      • 1970-01-01
      • 2011-04-30
      • 2018-07-26
      • 2019-07-11
      相关资源
      最近更新 更多