When I am using a specific program (Dolphin), my Esc hotkey closes it entirely, but I want different functionality for specific (sub-)windows. So far, I've been using #IfWinActive combined with GroupAdd.

Here is the documentation on the #IfWinActive command: https://autohotkey.com/docs/commands/_IfWinActive.htm
GroupAdd: https://autohotkey.com/docs/commands/GroupAdd.htm

If the GroupAdd command allowed one to exclude multiple titles from the ExcludeTitle parameter, I would have solved the problem by now. ExcludeTitle does not accept ahk_group.

I'm hoping for something more elegant than each hotkey having an IfWinNotActive ahk_group exceptions clause. I want the hotkey to work everywhere in the program except for the few specific (sub-)windows, so I'd rather something like one line of GroupAdd, AllOfTheProgramExceptExceptions, ahk_exe Dolphin.exe, exceptions or a few lines of GroupAdd, AllOfTheProgramExceptExceptions, ahk_exe Dolphin.exe, exception123 than making an ahk_group of all of the program's windows (which I don't know and would have to add to over time) except for the exceptions.

2 Answers 2

WinGet, id, list, ahk_exe Dolphin.exe
Loop, %id%
this_ID := id%A_Index%
; WinGet, exStyle, exStyle, ahk_id %this_ID%
; If !(exStyle & 0x100)
        ; Continue
    GroupAdd, Dolphin_group_WithoutExceptions, ahk_id %this_ID%
WinGetTitle, title, ahk_id %this_ID%
IfInString, title, ExcludeTitle1
    GroupAdd, Dolphin_group_exception1, ahk_id %this_ID%
IfInString, title, ExcludeTitle2
    GroupAdd, Dolphin_group_exception2, ahk_id %this_ID%
    GroupAdd, Dolphin_group_ExceptExceptions, ahk_id %this_ID%

F1:: GroupActivate, Dolphin_group_exception1
F2:: GroupActivate, Dolphin_group_exception2
F3:: GroupActivate, Dolphin_group_ExceptExceptions
F4:: GroupActivate, Dolphin_group_WithoutExceptions
  • 1
    So your method generates a new ahk_group of all the program's windows except the exceptions? It would seem that for my purpose, I would regenerate this ahk_group every time I activate a hotkey. I appreciate the contribution. I learned of an alternative that I will post when I have time. The alternative in short is that the WinTitle parameter of GroupAdd accepts ahk_group.
    – NiteCyper
    Mar 15, 2016 at 15:16

I learned that the WinTitle parameter of GroupAdd accepts ahk_group, thanks to fab12. I read it several times before, but I didn't understand their code/solution until a day or few later.

GroupAdd, AllOfTheProgramExceptExceptions1, ahk_exe Dolphin.exe, , , exception1 ; Make a group of all of the program's windows excluding window 1. ahk_class & ahk_exe not accepted by ExcludeTitle parameter.
GroupAdd, AllOfTheProgramExceptExceptions, ahk_group AllOfTheProgramExceptExceptions1, , , exception2 ; Make a group consisting of the previous group excluding window 2.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .