使用 autohotkey 在组中激活最近活跃的 window

Activate most recently active window in a group with autohotkey

我正在制作一个自动热键脚本来切换到文本编辑器,但根据我的工作,我可能有不同的文本编辑器。

我用我的三个文本编辑器创建了一个 TextEditor 组:

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

组似乎创建正确,但每当我使用 GroupActivate, TextEditor, R 它总是打开 Nodepad++ 并重复按下三个编辑器之间的切换。

我希望它首先打开我上次使用的任何内容,就像我正在使用 Code 并切换到另一个程序时它应该再次激活 Code。

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