【问题标题】:Activate most recently active window in a group with autohotkey使用自动热键激活组中最近活动的窗口
【发布时间】:2018-11-11 13:43:23
【问题描述】:

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

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

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

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

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

【问题讨论】:

    标签: autohotkey


    【解决方案1】:
    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

    【讨论】:

    • 这很好用。我之前已经在使用 WinGet, id, list 将某个类中的所有窗口都放在前面,只是没想到用它来获取最顶层的窗口
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-19
    • 2017-04-12
    • 1970-01-01
    • 1970-01-01
    • 2014-09-24
    相关资源
    最近更新 更多