; https://autohotkey.com/board/topic/52685-winactivate-on-a-specific-ie-browser-tab/ ; https://autohotkey.com/boards/viewtopic.php?f=6&t=30527 ; not all of these work IEGoOld(URL, TabName := "", show := True, timeout :=10,extrawait :=0,traytiptext := "") { /* wb.FullScreen := True wb.AddressBar := False wb.ToolBar := False wb.MenuBar := False wb.StatusBar := False wb.StatusText := "" wb.Visible := true wb.LocationURL wb.Navigate(URL) wb.Left wb.Top wb.Height wb.Width wb.HWND wb.Busy wb.Fullscreen := true wb.GoBack wb.GoForward wb.GoHome wb.GoSearch wb.Navigate("URL") wb.Quit wb.Refresh wb.Stop */ AccOn := true if traytiptext Traytip("","Connecting to " . traytiptext) verbose := true ;ComObjError(ShowComErrors) if verbose { ; clear oSciTE := ComObjActive("SciTE4AHK.Application") oSciTe.Message(0x111,420) ; Clear } if (ACCOn and Tabname) { ; Search for pre-existing ie tab For wb in ComObjCreate("Shell.Application").Windows { if verbose and InStr(wb.FullName, "iexplore.exe"), out("Checking (" . A_Index . ") '" . TabName . "' in '" . wb.LocationName . "' Tab = " . InStr(wb.LocationName,TabName)) If Instr(wb.LocationName,TabName) and InStr(wb.FullName, "iexplore.exe") { window:=0, client:=-4 ; constants for ie 11, varies on other versions ControlGet hwnd, hwnd, , DirectUIHWND2, % "ahk_class IEFrame ahk_id " wb.hwnd ; get control hwnd if not hwnd ControlGet hwnd, hwnd, , DirectUIHWND3, % "ahk_class IEFrame ahk_id " wb.hwnd ; get control hwnd if verbose, out("`tHandle for " . TabName . " @ " . hwnd) client := Acc_ObjectFromWindow(hwnd, client) ;note - the client object should be the 4th child of the window page_tab_list := Acc_Children(client)[1] for each, child in Acc_Children(page_tab_list) { if verbose, out("`t`tLooking @ '" . TabName . "' in '" . child.accName(0) . "' : " . InStr(child.accName(0),TabName) ) if InStr(child.accName(0),TabName) { if verbose, out("`t`t`tActivating " . child.accName(0)) child.accDoDefaultAction(0) ; Selects correct tab Winactivate, % wb.LocationName return wb } } } } } ; No ie tab found, so create it wb := ComObjCreate("InternetExplorer.Application") /* if not show { wb.top := 0 wb.left := 0 wb.width := 0 wb.height := 0 } */ if (show = "transparent") ; transparent needed to allow ACC interaction, made small for less eye catching WinSet, Transparent, 0, A else if (show) { wb.Visible := true WinMaximize, A } else wb.Visible := false if verbose, out("Creating New '" . TabName . "'") if (URL and wb.LocationURL != URL) { wb.Navigate(URL) IEWaitReady(wb,timeout,extrawait) } return wb } IEGet(Name="") { IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs" : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer.*" ) For Pwb in ComObjCreate( "Shell.Application" ).Windows If ( Pwb.LocationName = Name ) && InStr( Pwb.FullName, "iexplore.exe" ) Return Pwb } IEGet2(name="") { for obj in ComObjCreate("Shell.Application").Windows If !obj.AddressBar && (obj.document.title==RegExReplace(name,".*\K\h-.*")) break return obj } TabWinID(tabName) { WinGet, winList, List, ahk_class IEFrame While, winList%A_Index% { n:=A_Index, ErrorLevel:=0 While, !ErrorLevel { ControlGetText, tabText, TabWindowClass%A_Index%, % "ahk_id" winList%n% if InStr(tabText, tabName) return, winList%n% } } } TabActivate(hwnd, tabName) { ControlGet, hTabUI , hWnd,, DirectUIHWND1, ahk_id %hwnd% Acc := Acc_ObjectFromWindow(hTabUI) ;// access "Tabs" control If (Acc.accChildCount > 1) ;// more than 1 tab tabs := Acc.accChild(3) ;// access just "IE document tabs" While (tabs.accChildCount >= A_Index) { tab := tabs.accChild(A_Index) If (tab.accName(0) = tabName) ;// test vs. "tabName" return tab.accDoDefaultAction(0) ;// invoke tab } } IESelTab(tabName) { WinGet, winList, List, ahk_class IEFrame WinActivate, ahk_class IEFrame Send, ^1 While, winList%A_Index% { n:=A_Index, ErrorLevel:=0 While, !ErrorLevel { ControlGetText, tabText, TabWindowClass%A_Index%, % "ahk_id" winList%n% if InStr(tabText, tabName) { ;WinActivate, ahk_class IEFrame ;Send, ^%A_Index% return } } } } ; AutoHotkey_L: WBGet(WinTitle="ahk_class IEFrame", Svr#=1) { ; based on ComObjQuery docs static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT") , IID := "{0002DF05-0000-0000-C000-000000000046}" ; IID_IWebBrowserApp ; , IID := "{332C4427-26CB-11D0-B483-00C04FD90119}" ; IID_IHTMLWindow2 SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle% if (ErrorLevel != "FAIL") { lResult:=ErrorLevel, VarSetCapacity(GUID,16,0) if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 { DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc) return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc) } } } ; AHK Basic: WBGet(WinTitle="ahk_class IEFrame", Svr#=1) ; based on Sean's GetWebBrowser function { static msg, IID := "{332C4427-26CB-11D0-B483-00C04FD90119}" ; IID_IWebBrowserApp if Not msg msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT") SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle% if (ErrorLevel != "FAIL") { lResult:=ErrorLevel, GUID:=COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}") DllCall("oleacc\ObjectFromLresult", "Uint",lResult, "Uint",GUID, "int",0, "UintP",pdoc) return COM_QueryService(pdoc,IID,IID), COM_Release(pdoc) } } IELoad(Pwb) { Loop Sleep, 50 Until (pwb.readyState=4 && pwb.document.readyState="complete" && !pwb.busy) } IE_GetTabCount(hWnd) { loop { ControlGet, pHwnd, Hwnd,, DirectUIHWND%A_Index%, ahk_id %Hwnd% phwnd?cHwnd:=pHwnd } until !phwnd oAcc := Acc_Get("Object", "4.1", 0, "ahk_id " cHwnd) for each, oChild in Acc_Children(oAcc) { vTabText := oChild.accName(0) if (vTabText == "New tab (Ctrl+T)") vCount++ } oAcc := oChild := "" return vCount } ;================================================== IE_GetTabNames(hWnd, vSep="`n") { loop { ControlGet, pHwnd, Hwnd,, DirectUIHWND%A_Index%, ahk_id %Hwnd% phwnd?cHwnd:=pHwnd } until !phwnd oAcc := Acc_Get("Object", "4.1", 0, "ahk_id " cHwnd) vOutput := "" for each, oChild in Acc_Children(oAcc) { vTabText := oChild.accName(0) if !(vTabText == "New tab (Ctrl+T)") vOutput .= vTabText vSep } ;~ vOutput := SubStr(vOutput, 1, -StrLen(vSep)) ;trim right oAcc := oChild := "" return vOutput } ;================================================== IE_FocusTabByNum(hWnd, vNum) { loop { ControlGet, pHwnd, Hwnd,, DirectUIHWND%A_Index%, ahk_id %Hwnd% phwnd?cHwnd:=pHwnd } until !phwnd oAcc := Acc_Get("Object", "4.1", 0, "ahk_id " cHwnd) if !Acc_Children(oAcc)[vNum] vNum := "" else Acc_Children(oAcc)[vNum].accDoDefaultAction(0) oAcc := "" WinActivate, ahk_id %hWnd% return vNum } ;================================================== IE_FocusTabByName(hWnd, vTitle, vNum=1) { loop { ControlGet, pHwnd, Hwnd,, DirectUIHWND%A_Index%, ahk_id %Hwnd% phwnd?cHwnd:=pHwnd } until !phwnd oAcc := Acc_Get("Object", "4.1", 0, "ahk_id " cHwnd) vCount := 0, vRet := 0 for each, oChild in Acc_Children(oAcc) { vTabText := oChild.accName(0) if (vTabText = vTitle) vCount++ if (vCount = vNum) { oChild.accDoDefaultAction(0), vRet := A_Index break } } oAcc := oChild := "" WinActivate, ahk_id %hWnd% return vRet } ;==================================================