1
votes

In AutoHotKey, ahk_class NAME has been a good identifier for programs. Typically, I now use it in the following two ways:

  1. Simply calling the most recently called active instance:
    ; Pressing Win+Shift+X will bring up (or switch to) the Windows Journal
    Application
    #+x:: 
    IfWinExist ahk_class JournalApp
        WinActivate ahk_class JournalApp
    else 
        Run C:\Program Files\Windows Journal\Journal.exe
    return
  1. Grouping windows with the same ahk_class and looping through them:
    GroupAdd, FIRE, ahk_class MozillaWindowClass

    ; Pressing Win+3 will go through all open Firefox windows one by one.
    #3::
    IfWinExist ahk_class MozillaWindowClass
        GroupActivate, FIRE, r
    else
        Run firefox
    return

However, there are certain programs that do not have a stable ahk_class name. For example, the ArcMap.exe should display the following information in the "Windows Spy" window of AHK:

>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
Untitled - ArcMap
ahk_class Afx:012F0000:b:00010003:00000006:001C0BB0

Any idea how could I refer to this application that has dynamic ahk_class?

I am aware that there is also something called ahk_exe. However, I did not find it compatible with the method GroupAdd, GroupActivate or IfWinExist.

1
What version of Autohotkey are you using ? msgbox % A_AhkVersion as ahk_exe needs v1.1.01+ ahkscript.org/download/ahk-install.exe - blackholyman
@blackholyman, thank you! You are right. I am running v1.0.*** version. Updating the AHK distribution in the background solves all the concern. - llinfeng

1 Answers

2
votes

You definitely are on the right track trying to incorporate ahk_exe. GroupAdd (and every other command receiving a WinTitle parameter at that) is compatible with ahk_exe in AHK_L; this sample code works perfectly on my machine:

GroupAdd, notepad, ahk_exe notepad.exe
Run, notepad.exe
WinWaitActive, ahk_group notepad
Sleep, 1000
WinClose, ahk_group notepad

I suspect you're not using the most recent version of AHK. Get it here and have another try.