Autohotkey 使用自动热键激活组中最近激活的窗口

Autohotkey 使用自动热键激活组中最近激活的窗口,autohotkey,Autohotkey,我正在制作一个自动热键脚本以切换到文本编辑器,但根据我的工作内容,可能会有不同的文本编辑器 我用我的三个文本编辑器创建了一个组文本编辑器: GroupAdd, TextEditor, ahk_class Notepad++ GroupAdd, TextEditor, ahk_exe Code.exe GroupAdd, TextEditor, ahk_class Notepad 该组似乎创建得很正确,但每当我使用GroupActivate,TextEditor,R时,它总是打开Nodepad+

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

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

GroupAdd, TextEditor, ahk_class Notepad++
GroupAdd, TextEditor, ahk_exe Code.exe
GroupAdd, TextEditor, ahk_class Notepad
该组似乎创建得很正确,但每当我使用
GroupActivate,TextEditor,R
时,它总是打开Nodepad++并反复按下三个编辑器之间的开关

我希望它能打开我上次第一次使用的任何东西,就像我在使用代码并切换到另一个程序时,它会再次激活代码一样

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

这很有效。我之前已经在使用WinGet、id、list将某个类中的所有窗口放在前面,只是没有想到使用它来获取最上面的窗口