9

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.

Ehryk
  • 1,930
  • 2
  • 27
  • 47
  • What's wrong with duplicating them? –  Feb 23 '13 at 18:43
  • 1
    If I add a shortcut, I have to remember to add it twice. This could get cumbersome if it's more than 'just twice', and it's inelegant, and I'm looking for a way around it. – Ehryk Feb 23 '13 at 20:13

6 Answers6

10

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!

Robert Ilbrink
  • 7,738
  • 2
  • 22
  • 32
8

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
Robert Ilbrink
  • 7,738
  • 2
  • 22
  • 32
  • Yeah, it looks like I'm going to have to resort to groups. In the purest form of the question, I was wondering if 'or' was possible (see the last line); it's looking like it isn't. If there isn't a proper or answer posted in a day or so, I'll mark this as the answer. Thanks for your help! – Ehryk Feb 24 '13 at 00:38
  • I should note, GroupAdd statements should be at the very beginning of your script, otherwise, it won't work. – Shayan Dec 02 '18 at 23:48
5

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.

Francis Huang
  • 550
  • 5
  • 6
4

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.

Mac7
  • 41
  • 2
-1

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

#IfWinActive (ahk_class cygwin or ahk_class mintty)
Robert Ilbrink
  • 7,738
  • 2
  • 22
  • 32
-1

I found an example that uses this format:

#IfWinActive ahk_class ExploreWClass|CabinetWClass

See: Best AutoHotKey macros?

Community
  • 1
  • 1
Robert Ilbrink
  • 7,738
  • 2
  • 22
  • 32