Ehryk
Ehryk

Reputation: 1990

How do I use 'or's in AutoHotKey scripts?

I have been browsing the AutoHotKey documentation, and I don't see a clear use of how to use 'or' in context specific hot keys. On my setup, Cygwin will either launch with ahk_class cygwin (when I use the context menu) or mintty (when I use the .bat or exe directly).

Currently, I duplicate the hotkeys into two separate blocks,

#IfWinActive ahk_class cygwin
...
#IfWinActive
#IfWinActive ahk_class mintty
...
#IfWinActive

Is there a way to combine them? I've tried:

#IfWinActive ahk_class cygwin ahk_class mintty
#IfWinActive ahk_class || cygwin ahk_class mintty
#IfWinActive ahk_class or cygwin ahk_class mintty
#IfWinActive ahk_class cygwin || #IfWinActive ahk_class mintty
#IfWinActive ahk_class cygwin or #IfWinActive ahk_class mintty
#IfWinActive (ahk_class cygwin or ahk_class mintty)
#IfWinActive (ahk_class cygwin || ahk_class mintty)
#IfWinActive ahk_class cygwin|mintty
#IfWinActive ahk_class cygwin||mintty 

...and none of these seem to work. This post states this can be accomplished with groups, but I'm looking for a way to combine them in a single statement.

Upvotes: 9

Views: 3184

Answers (6)

Mac7
Mac7

Reputation: 41

I know the question is outdated, but for those who are looking for a solution to this

#if WinActive("ahk_class cygwin") or WinActive("ahk_class mintty") 

is working.

Upvotes: 4

Francis Huang
Francis Huang

Reputation: 550

You could also try the following, I tested and it was working for me (AutoHotkey v1.1.14.01):

SetTitleMatchMode, REGEX

#IfWinActive (cygwin)|(mintty)

This uses the built-in OR mechanism of regular expressions. I couldn't get groups to work for some reason.

Upvotes: 5

Robert Ilbrink
Robert Ilbrink

Reputation: 7953

OK, last one (and tested).

#If WinActive("ahk_class ExploreWClass") || WinActive("ahk_class CabinetWClass")

Oh b.t.w. I use AutoHotKey_L, which supports #If!

Upvotes: 10

Robert Ilbrink
Robert Ilbrink

Reputation: 7953

Alright, I remember, after seeing an other example: Define a GroupName with multiple ahk_class entries....

GroupAdd, GroupName, ahk_class ExploreWClass
GroupAdd, GroupName, ahk_class CabinetWClass
#IfWinActive ahk_group GroupName

Upvotes: 8

Robert Ilbrink
Robert Ilbrink

Reputation: 7953

I found an example that uses this format:

#IfWinActive ahk_class ExploreWClass|CabinetWClass

See: Best AutoHotKey macros?

Upvotes: -1

Robert Ilbrink
Robert Ilbrink

Reputation: 7953

Could you try this: It is the way I do this with regular IF statements.

#IfWinActive (ahk_class cygwin or ahk_class mintty)

Upvotes: -1

Related Questions