Search code examples
autohotkey

Check if a window has a empty title and a certain ahk_class name?


I am dealing with an application that has many panels, all of its panels (not including its main window) share the same ahk_class name, this includes the temporary menu bar panels

After some investigation. I have learnt that the temporary menu bar panels don't have a window title but all the panels have a window title: For example Menubar > Edit Panel :


;ahk_class 742DEA58-ED6B-4402-BC11-20DFC6D08040-6571DDC4-B3AA-45e4-9D35-57C0C1E90AD5
;ahk_exe CLIPStudioPaint.exe

And a panel called Layers, belonging to the application:

; Layer
; ahk_class 742DEA58-ED6B-4402-BC11-20DFC6D08040-6571DDC4-B3AA-45e4-9D35-57C0C1E90AD5
; ahk_exe CLIPStudioPaint.exe

I want to only target the menu bar, with something like:

Space::
WinWaitActive, ahk_class 742DEA58-ED6B-4402-BC11-20DFC6D08040-6571DDC4-B3AA-45e4-9D35-57C0C1E90AD5
MsgBox, Found

Regarding the above code, the message box will trigger if focus is also given to one of the panels, or if a panel was active at the time of triggering hotkey.

I would like it to only trigger if a menu bar window is found, is this possible?

Thanks.


Solution

  • You can check for an empty title in ahk by using regex. ^$ are the start and end of regex chars directly after each other, which matches an empty string. To do that, set the TitleMatchMode to "Regex" and run your command like this:

    SetTitleMatchMode, RegEx
    WinWaitActive, i)^$ ahk_class i)742DEA58-ED6B-4402-BC11-20DFC6D08040-6571DDC4-B3AA-45e4-9D35-57C0C1E90AD5
    

    Note the i) before each filter term. In regex mode you need them if you have multiple. Since that is a bit annoying, you can reset the TitleMatchMode afterwards like this:

    TitleMatchMode := A_TitleMatchMode
    SetTitleMatchMode, RegEx
    WinWaitActive, i)^$ ahk_class i)742DEA58-ED6B-4402-BC11-20DFC6D08040-6571DDC4-B3AA-45e4-9D35-57C0C1E90AD5
    SetTitleMatchMode, % TitleMatchMode
    

    Tested and it works for me, but if you have any issues, I'd be happy to help. Just ran into the same issue, found this post but no answers, came up with a solution and decided to share, even if the question is old and you don't care but maybe others do.