Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 441
Ehryk Avatar asked Feb 23 '13 18:02

Ehryk


People also ask

What does := mean in AutoHotkey?

Var := expressionEvaluates an expression and stores the result in a variable.

How do I send keystrokes in AutoHotkey?

Send +{TAB 4} ; Presses Shift-Tab 4 times. To hold down or release a key: Enclose in braces the name of the key followed by the word Down or Up. For example: Send {b down}{b up} Send {TAB down}{TAB up} Send {Up down} ; Press down the up-arrow key.

Can AutoHotkey record keystrokes?

AutoHotkey definitely does not have built-in recording capabilities--you would need to use a third party macro recorder if you don't want to just code the macro from scratch.


2 Answers

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
like image 85
Robert Ilbrink Avatar answered Oct 31 '22 01:10

Robert Ilbrink


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.

like image 5
Francis Huang Avatar answered Oct 31 '22 00:10

Francis Huang