2
votes

I am making an autohotkey script to switch to a text editor, but depending on what I'm working on I may have different text editors.

I created a group TextEditor with my three text editors:

GroupAdd, TextEditor, ahk_class Notepad++
GroupAdd, TextEditor, ahk_exe Code.exe
GroupAdd, TextEditor, ahk_class Notepad

The group seems to be created properly but whenever I use GroupActivate, TextEditor, R it always opens Nodepad++ and repeated presses switch between the three editors.

I want it to open whatever I last used first, like if I was using Code and switched to another program it should activate Code again.

1

1 Answers

2
votes
GroupAdd, TextEditor, ahk_class Notepad++
GroupAdd, TextEditor, ahk_exe Code.exe
GroupAdd, TextEditor, ahk_class Notepad

F1::
IfWinActive ahk_group TextEditor
    GroupActivate, TextEditor, R
else
{
    list := ""
    ; windows are retrieved in order from topmost to bottommost:
    WinGet, id, list, ahk_group TextEditor
    Loop, %id%
    {
        this_ID := id%A_Index%
        WinActivate, ahk_id %this_ID% ; activate the most recently active window in this group
            break
    }
}
return

https://autohotkey.com/docs/commands/WinGet.htm#List