Hotkey if an operator using multiple conditional expressions

The following script works to open the location of Firefox / "awesome" anywhere using control-l , except when using Acrobat / Adobe reader. This is because control-l in Acrobat enters full-screen mode. It works, but it is ugly and uses the enclosed #ifWinNotActive .

 #IfWinNotActive, ahk_class MozillaWindowClass #IfWinNotActive, ahk_class ahk_class AcrobatSDIWindow ^l:: WinActivate, ahk_class MozillaWindowClass Send, ^l return #IfWinNotActive #IfWinNotActive 

The following code replacement does not work. Autohotkey does not complain about errors, but ignores WinActive conventions and also seems to end up in an endless loop. Any ideas why? (I tried the return statement both before and after the closing bracket.)

 ^l:: if (!WinActive(ahk_class,MozillaWindowClass)) and (!WinActive(ahk_class,AcrobatSDIWindow)) { WinActivate, ahk_class MozillaWindowClass Send, ^l } return 
+6
source share
1 answer

With the WinActive function, you need quotes around ahk_class MozillaWindowClass
and you don’t need a comma. An infinite loop can be resolved by adding hook $ .

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

However, recording this method is only necessary if you are using a basic version of AutoHotkey that is outdated.
Unless you have a legitimate reason not to upgrade to AutoHotkey_L (which is unlikely)
you can accomplish what you tried in the first example with the # If directive.

 #If !WinActive("ahk_class CalcFrame") && !WinActive("ahk_class Notepad") ^l:: Run, notepad Winwait, ahk_class Notepad Send, test Return f1::traytip,, test #If 

In this example, Ctrl + L and F1 will only work as coded if
the calculator and / or notepad is currently inactive,
otherwise they act as usual.

For those who are not familiar with the abbreviation AutoHotkey,! means no.

+7
source

Source: https://habr.com/ru/post/911633/


All Articles