热键if语句使用多个条件

Jef*_*rod 7 conditional autohotkey

以下脚本可以在任何地方使用打开Firefox的位置/"真棒"栏control-l,除非使用Acrobat/Adob​​e阅读器.这是因为control-l在Acrobat中全屏显示.它工作,但它很丑,并使用嵌套#ifWinNotActive.

#IfWinNotActive, ahk_class MozillaWindowClass
#IfWinNotActive, ahk_class ahk_class AcrobatSDIWindow
^l::
WinActivate, ahk_class MozillaWindowClass
Send, ^l
return
#IfWinNotActive
#IfWinNotActive
Run Code Online (Sandbox Code Playgroud)

以下代码替换不起作用.Autohotkey不会抱怨错误,但忽略了!WinActive条件,而且似乎陷入无限循环.有什么想法吗?(我在结束括号前后都尝试了return语句.)

^l::
if (!WinActive(ahk_class,MozillaWindowClass)) and (!WinActive(ahk_class,AcrobatSDIWindow)) {
   WinActivate, ahk_class MozillaWindowClass
   Send, ^l
}
return
Run Code Online (Sandbox Code Playgroud)

Hon*_*Abe 8

使用WinActive功能,您需要引用ahk_class MozillaWindowClass
并且不需要逗号.可以通过添加钩子 来解决无限循环$.

$^l::
if (!WinActive("ahk_class MozillaWindowClass"))
   and (!WinActive("ahk_class AcrobatSDIWindow")) 
{
   WinActivate, ahk_class MozillaWindowClass
   Send, ^l
} else
   Send, ^l
Return
Run Code Online (Sandbox Code Playgroud)

但是,只有在使用过时的AutoHotkey basic时才需要这样写.
除非您有正当理由不升级到AutoHotkey_L(这不太可能),否则您
可以使用#If指令完成第一个示例中的操作.

#If !WinActive("ahk_class CalcFrame") && !WinActive("ahk_class Notepad")

^l::
Run, notepad
Winwait, ahk_class Notepad
Send, test
Return

f1::traytip,, test

#If
Run Code Online (Sandbox Code Playgroud)

在这个例子中Ctrl+ LF1只会工作,如编码,如果
计算器/记事本或当前不活动,
否则他们充当他们通常会.

对于不熟悉AutoHotkey简写的人,!意味着没有.