r/AutoHotkey • • 29d ago

v2 Tool / Script Share Open link in Split View Edge Browser

1 Upvotes

1 comment sorted by

4

u/Keeyra_ 29d ago edited 29d ago

Instead of navigating the context menu with keypresses like a caveman, which is prone to all sorts of errors, you can actually read the context menu and have the script click the desired button.

#Requires AutoHotkey 2.0
#SingleInstance
#Include <UIA>

#HotIf WinActive("ahk_exe msedge.exe")
F8:: {
    Click("R")
    Sleep(50)
    try {
        edgeEl := UIA.ElementFromHandle("ahk_exe msedge.exe")
        if edgeEl {
            splitItem := edgeEl.FindFirst({ Name: "Open link in split screen window", Type: "MenuItem" })
            if splitItem {
                splitItem.Click()
                return
            }
        }
    } catch {
        Send("{Escape}")
    }
}
#HotIf

Or click the 4th, making it language neutral.

#Requires AutoHotkey 2.0
#SingleInstance
#Include <UIA>

#HotIf WinActive("ahk_exe msedge.exe")
F8:: {
    Click("R")
    Sleep(50)
    try {
        edgeEl := UIA.ElementFromHandle("ahk_exe msedge.exe")
        if edgeEl {
            items := edgeEl.FindAll({ Type: "MenuItem" })
            if items.Length >= 4 {
                items[4].Click()
                return
            }
        }
    } catch {
        Send("{Escape}")
    }
}
#HotIf

Courtesy of u/Individual_Check4587 (Descolada)s' UIA.

You could even go the extra mile and have it check if you are actually over an URL to begin with.