使用自动热键快捷方式在 Chrome 窗口之间移动



我花了几个小时试图弄清楚如何使用Autohotkey快捷方式在特定Chrome窗口之间切换。

我有两个显示器。左侧监视器(nr 1)在Chrome本地主机窗口和Vim编辑器之间垂直拆分。右侧显示器(nr 2)具有Chrome全屏,带有我的gmail,搜索标签等。

我想使用 ahk 快捷方式在窗口之间切换,例如 Alt+1(本地主机监视器 nr 1)、Alt+2(Chrome 窗口监视器 nr 2)。

如果窗口具有不同的标题,则很容易做到。我尝试使用标题,文本,ahk_id,ahk_class,sysget(更改焦点监视器),鼠标单击(被其他窗口覆盖)等。似乎没有什么是一致的,也无法谷歌任何明智的答案。

有什么想法吗?

这段代码应该适合你。一个热键来激活最左侧的铬窗口。另一个是活动最右边

CoordMode, Pixel, Screen
!1::
    ChromeList := GetWinListByClass("Chrome_WidgetWin_1")
    LeftmostPos := 9999
    LeftmostId := ""
    Loop, % ChromeList.MaxIndex()
    {
        currentId := ChromeList[A_Index][1]
        currentX := ChromeList[A_Index][2]
        if (currentX < LeftmostPos)
        {
            LeftmostPos := currentX
            LeftmostId := currentId
        }
    }
    WinActivate, % "ahk_id" LeftmostId
    Return
!2::
    ChromeList := GetWinListByClass("Chrome_WidgetWin_1")
    RightmostPos := -9999
    RightmostId := ""
    Loop, % ChromeList.MaxIndex()
    {
        currentId := ChromeList[A_Index][1]
        currentX := ChromeList[A_Index][2]
        if (currentX > RightmostPos)
        {
            RightmostPos := currentX
            RightmostId := currentId
        }
    }
    WinActivate, % "ahk_id" RightmostId
    Return

GetWinListByClass(filterClass)
{
    WinGet, all, list
    ChromeList := {}
    winCount := 1
    Loop, %all%
    {
        WinGetClass, WClass, % "ahk_id " all%A_Index%
        if (WClass = filterClass)
        {
            winId := all%A_Index%
            WinGetPos, X, Y, W, H, % "ahk_id " winId 
            ChromeList[winCount] := [winId, X]
            winCount++
        }
    }
    return ChromeList
}

最新更新