Something i started working on - Inspiration came from Run1e's Columbus - perhaps he could implement this functionality into it?!
It will display all active windows - and activate whichever you click on. Also shows Chrome tabs(will be adding other browsers soon hopefully)
Alt+Z to activate
Esc to close
Screenshots:
http://imgur.com/a/CAPKI
http://imgur.com/a/h2qJM
Program code: Includes Just Me's LV_EX functions for groups
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance,Force
setbatchlines, -1
gui,margin,0
gui,-Border
gui,font,s10
gui, +alwaysontop
;Gui,Add,ListBox,x0 y0 h340 w400 vmylistbox gMyListBox CGray,
Gui,Add,Tab3,x0 y0 w400 h340,Active Windows|Browser Tabs
gui,tab,1
Gui, Add, Listview, x0 y0 w400 h340 Grid hwndHLV vVLV gVLV, Windows
Gui,Tab,2
Gui, Add, Listview, x0 y0 w400 h340 Grid hwndHLV2 vVLV2 gVLV2, Tabs
gui,listview,syslistview321
return
!z::
;WinGetPos xP, yP, wP, hP, ahk_class Shell_TrayWnd
IDs := []
browserids := []
WinGet, ws_IDList, List
groups=1
LV_Delete()
gui,listview,syslistview322
LV_Delete()
gui,listview,syslistview321
Newlist :={}
bCounter = 1
Loop % ws_IDList
{
winget,processlist,processname, % "ahk_id" ws_IdList%a_Index%
if(newlist[processlist] = "")
newlist[processlist,0] := ws_IdList%a_Index%
else
newlist[processlist,newlist[processlist].maxindex()+1] := ws_IdList%a_Index%
}
for k,v in newlist
{
LV_EX_GroupInsert(HLV, groups, k)
LV_EX_GroupSetState(HLV, groups, "Collapsible")
for window,hwnd in v
{
if(k="Chrome.exe"){
BrowserCounter+=100
BrowserCounter:=ListBrowser(hwnd)
}
winget,pName,processname, ahk_id %hwnd%
WinGetTitle,wTitle, ahk_id %hwnd%
if(((wTitle="Start") OR (wTitle = "Program Manager") AND k = "Explorer.exe")){
continue
}
if(wTitle <> "")
{
if(pName="Explorer.exe")
wTitle := "File Explorer - " wTitle
LV_Add("",wTitle)
IDs[wTitle] := hwnd
LV_EX_SetGroup(HLV,LV_GetCount(), Groups)
}
}
groups++
}
LV_EX_EnableGroupView(HLV)
LV_EX_EnableGroupView(HLV2)
LV_ModifyCol(A_Index, "AutoHdr")
gui,show, NA ;x1515 y735 h300 w400
return
VLV:
gui,listview,syslistview321
LV_GetText(Text,A_EventInfo)
winid := ids[text]
WinActivate, ahk_id %winid%
return
VLV2:
gui,listview,syslistview322
LV_GetText(bText,A_EventInfo)
chromeW := LV_EX_GetGroup(HLV2,A_EventInfo)
gui,listview,syslistview321
gHeader := StrSplit(LV_EX_GroupGetHeader(HLV2,ChromeW),"-").1
WinActivate, % "ahk_id" browserids[gheader]
list := Acc_Get("Object", "4.1.2.2.2", 0, "ahk_id" browserids[gHeader])
for each, tab in Acc_Children(list)
{
if (tab.accName(0) = bText)
{
tab.accDoDefaultAction(0)
return
}
}
return
ESC::
gui,Hide
return
ListBrowser(hwnd)
{
global
gui,listview,syslistview322
WinGet,wTitle,processname, ahk_id %hwnd%
LV_EX_GroupInsert(HLV2, hwnd, bcounter++ "-" wTitle)
browserids.push(hwnd)
LV_EX_GroupSetState(HLV2, hwnd, "Collapsible")
tabs:=""
list := Acc_Get("Object", "4.1.2.2.2", 0, "ahk_id" hwnd)
for each, tab in Acc_Children(list)
{
LV_Add("",tab.accName(0))
LV_EX_SetGroup(HLV2,LV_GetCount(), hwnd)
}
;tabs .= tab.accName(0) "`n"
gui,listview,syslistview321
return browserids
}
;Courtesy of Lexikos
WinGetNormalPos(hwnd, ByRef x, ByRef y, ByRef w="", ByRef h="")
{
VarSetCapacity(wp, 44), NumPut(44, wp)
DllCall("GetWindowPlacement", "uint", hwnd, "uint", &wp)
x := NumGet(wp, 28, "int")
y := NumGet(wp, 32, "int")
w := NumGet(wp, 36, "int") - x
h := NumGet(wp, 40, "int") - y
}
; ======================================================================================================================
; Namespace: LV_EX
; Function: Some additional functions to use with AHK ListView controls.
; Tested with: AHK 1.1.20.03 (A32/U32/U64)
; Tested on: Win 8.1 (x64)
; Changelog:
; 1.1.01.00/2016-04-28(just me - added LV_EX_GroupGetState contributed by Pulover.
; 1.1.00.00/2015-03-13/just me - added basic tile view support (suggested by toralf),
; added basic (XP compatible) group view support,
; revised code and made some minor changes.
; 1.0.00.00/2013-12-30/just me - initial release.
; Notes:
; In terms of Microsoft
; Item stands for the whole row or the first column of the row
; SubItem stands for the second to last column of a row
; All functions require the handle of the ListView (HWND). You get this handle using the 'Hwnd' option when
; creating the control per 'Gui, Add, HwndHwndOfLV ...' or using 'GuiControlGet, HwndOfLV, Hwnd, MyListViewVar'
; after control creation.
; Credits:
; LV_EX tile view functions:
; Initial idea by segalion (old forum: /board/topic/80754-listview-with-multiline-in-report-mode-help/)
; based on code from Fabio Lucarelli (http://users.skynet.be/oleole/ListView_Tiles.htm).
; ======================================================================================================================
; This software is provided 'as-is', without any express or implied warranty.
; In no event will the authors be held liable for any damages arising from the use of this software.
; ======================================================================================================================
; ======================================================================================================================
; LV_EX_EnableGroupView - Enables or disables whether the items in a list-view control display as a group.
; ======================================================================================================================
LV_EX_EnableGroupView(HLV, Enable := True) {
; LVM_ENABLEGROUPVIEW = 0x109D -> msdn.microsoft.com/en-us/library/bb774900(v=vs.85).aspx
SendMessage, 0x109D, % (!!Enable), 0, , % "ahk_id " . HLV
Return (ErrorLevel >> 31) ? 0 : 1
}
; ======================================================================================================================
; LV_EX_GetGroup - Gets the ID of the group the list-view item belongs to.
; ======================================================================================================================
LV_EX_GetGroup(HLV, Row) {
; LVM_GETITEMA = 0x1005 -> http://msdn.microsoft.com/en-us/library/bb774953(v=vs.85).aspx
Static OffGroupID := 28 + (A_PtrSize * 3)
LV_EX_LVITEM(LVITEM, 0x00000100, Row) ; LVIF_GROUPID
SendMessage, 0x1005, 0, % &LVITEM, , % "ahk_id " . HLV
Return NumGet(LVITEM, OffGroupID, "UPtr")
}
; ======================================================================================================================
; LV_EX_GetHeader - Retrieves the handle of the header control used by the list-view control.
; ======================================================================================================================
LV_EX_GetHeader(HLV) {
; LVM_GETHEADER = 0x101F -> http://msdn.microsoft.com/en-us/library/bb774937(v=vs.85).aspx
SendMessage, 0x101F, 0, 0, , % "ahk_id " . HLV
Return ErrorLevel
}
; ======================================================================================================================
; LV_EX_GroupGetHeader - Gets the header text of a group by group ID
; ======================================================================================================================
LV_EX_GroupGetHeader(HLV, GroupID, MaxChars := 1024) {
; LVM_GETGROUPINFO = 0x1095
Static SizeOfLVGROUP := (4 * 6) + (A_PtrSize * 4)
Static LVGF_HEADER := 0x00000001
Static OffHeader := 8
Static OffHeaderMax := 8 + A_PtrSize
VarSetCapacity(HeaderText, MaxChars * 2, 0)
VarSetCapacity(LVGROUP, SizeOfLVGROUP, 0)
NumPut(SizeOfLVGROUP, LVGROUP, 0, "UInt")
NumPut(LVGF_HEADER, LVGROUP, 4, "UInt")
NumPut(&HeaderText, LVGROUP, OffHeader, "Ptr")
NumPut(MaxChars, LVGROUP, OffHeaderMax, "Int")
SendMessage, 0x1095, %GroupID%, % &LVGROUP, , % "ahk_id " . HLV
Return StrGet(&HeaderText, MaxChars, "UTF-16")
}
; ======================================================================================================================
; LV_EX_GroupGetState - Get group states (requires Win Vista+ for most states).
; ======================================================================================================================
LV_EX_GroupGetState(HLV, GroupID, ByRef Collapsed := "", ByRef Collapsible := "", ByRef Focused := "", ByRef Hidden := ""
, ByRef NoHeader := "", ByRef Normal := "", ByRef Selected := "") {
; LVM_GETGROUPINFO = 0x1095 -> msdn.microsoft.com/en-us/library/bb774932(v=vs.85).aspx
Static OS := DllCall("GetVersion", "UChar")
Static LVGS5 := {Collapsed: 0x01, Hidden: 0x02, Normal: 0x00}
Static LVGS6 := {Collapsed: 0x01, Collapsible: 0x08, Focused: 0x10, Hidden: 0x02, NoHeader: 0x04, Normal: 0x00, Selected: 0x20}
Static LVGF := 0x04 ; LVGF_STATE
Static SizeOfLVGROUP := (4 * 6) + (A_PtrSize * 4)
Static OffStateMask := 8 + (A_PtrSize * 3) + 8
Static OffState := OffStateMask + 4
SetStates := 0
LVGS := OS > 5 ? LVGS6 : LVGS5
For Each, State In LVGS
SetStates |= State
VarSetCapacity(LVGROUP, SizeOfLVGROUP, 0)
NumPut(SizeOfLVGROUP, LVGROUP, 0, "UInt")
NumPut(LVGF, LVGROUP, 4, "UInt")
NumPut(SetStates, LVGROUP, OffStateMask, "UInt")
SendMessage, 0x1095, %GroupID%, &LVGROUP, , % "ahk_id " . HLV
States := NumGet(&LVGROUP, OffState, "UInt")
For Each, State in LVGS
%Each% := States & State ? True : False
Return ErrorLevel
}
; ======================================================================================================================
; LV_EX_GroupInsert - Inserts a group into a list-view control.
; ======================================================================================================================
LV_EX_GroupInsert(HLV, GroupID, Header, Align := "", Index := -1) {
; LVM_INSERTGROUP = 0x1091 -> msdn.microsoft.com/en-us/library/bb761103(v=vs.85).aspx
Static Alignment := {1: 1, 2: 2, 4: 4, C: 2, L: 1, R: 4}
Static SizeOfLVGROUP := (4 * 6) + (A_PtrSize * 4)
Static OffHeader := 8
Static OffGroupID := OffHeader + (A_PtrSize * 3) + 4
Static OffAlign := OffGroupID + 12
Static LVGF := 0x11 ; LVGF_GROUPID | LVGF_HEADER | LVGF_STATE
Static LVGF_ALIGN := 0x00000008
Align := (A := Alignment[SubStr(Align, 1, 1)]) ? A : 0
Mask := LVGF | (Align ? LVGF_ALIGN : 0)
PHeader := A_IsUnicode ? &Header : LV_EX_PWSTR(Header, WHeader)
VarSetCapacity(LVGROUP, SizeOfLVGROUP, 0)
NumPut(SizeOfLVGROUP, LVGROUP, 0, "UInt")
NumPut(Mask, LVGROUP, 4, "UInt")
NumPut(PHeader, LVGROUP, OffHeader, "Ptr")
NumPut(GroupID, LVGROUP, OffGroupID, "Int")
NumPut(Align, LVGROUP, OffAlign, "UInt")
SendMessage, 0x1091, %Index%, % &LVGROUP, , % "ahk_id " . HLV
Return ErrorLevel
}
; ======================================================================================================================
; LV_EX_GroupRemove - Removes a group from a list-view control.
; ======================================================================================================================
LV_EX_GroupRemove(HLV, GroupID) {
; LVM_REMOVEGROUP = 0x1096 -> msdn.microsoft.com/en-us/library/bb761149(v=vs.85).aspx
SendMessage, 0x10A0, %GroupID%, 0, , % "ahk_id " . HLV
Return ErrorLevel
}
; ======================================================================================================================
; LV_EX_GroupRemoveAll - Removes all groups from a list-view control.
; ======================================================================================================================
LV_EX_GroupRemoveAll(HLV) {
; LVM_REMOVEALLGROUPS = 0x10A0 -> msdn.microsoft.com/en-us/library/bb761147(v=vs.85).aspx
SendMessage, 0x10A0, 0, 0, , % "ahk_id " . HLV
Return ErrorLevel
}
; ======================================================================================================================
; LV_EX_GroupSetState - Set group state (requires Win Vista+ for most states).
; ======================================================================================================================
LV_EX_GroupSetState(HLV, GroupID, States*) {
; LVM_SETGROUPINFO = 0x1093 -> msdn.microsoft.com/en-us/library/bb761167(v=vs.85).aspx
Static OS := DllCall("GetVersion", "UChar")
Static LVGS5 := {Collapsed: 0x01, Hidden: 0x02, Normal: 0x00, 0: 0, 1: 1, 2: 2}
Static LVGS6 := {Collapsed: 0x01, Collapsible: 0x08, Focused: 0x10, Hidden: 0x02, NoHeader: 0x04, Normal: 0x00
, Selected: 0x20, 0: 0, 1: 1, 2: 2, 4: 4, 8: 8, 16: 16, 32: 32}
Static LVGF := 0x04 ; LVGF_STATE
Static SizeOfLVGROUP := (4 * 6) + (A_PtrSize * 4)
Static OffStateMask := 8 + (A_PtrSize * 3) + 8
Static OffState := OffStateMask + 4
SetStates := 0
LVGS := OS > 5 ? LVGS6 : LVGS5
For Each, State In States {
If !LVGS.HasKey(State)
Return False
SetStates |= LVGS[State]
}
VarSetCapacity(LVGROUP, SizeOfLVGROUP, 0)
NumPut(SizeOfLVGROUP, LVGROUP, 0, "UInt")
NumPut(LVGF, LVGROUP, 4, "UInt")
NumPut(SetStates, LVGROUP, OffStateMask, "UInt")
NumPut(SetStates, LVGROUP, OffState, "UInt")
SendMessage, 0x1093, %GroupID%, % &LVGROUP, , % "ahk_id " . HLV
Return ErrorLevel
}
; ======================================================================================================================
; LV_EX_HasGroup - Determines whether the list-view control has a specified group.
; ======================================================================================================================
LV_EX_HasGroup(HLV, GroupID) {
; LVM_HASGROUP = 0x10A1 -> msdn.microsoft.com/en-us/library/bb761097(v=vs.85).aspx
SendMessage, 0x10A1, %GroupID%, 0, , % "ahk_id " . HLV
Return ErrorLevel
}
; ======================================================================================================================
; LV_EX_IsGroupViewEnabled - Checks whether the list-view control has group view enabled.
; ======================================================================================================================
LV_EX_IsGroupViewEnabled(HLV) {
; LVM_ISGROUPVIEWENABLED = 0x10AF -> msdn.microsoft.com/en-us/library/bb761133(v=vs.85).aspx
SendMessage, 0x10AF, 0, 0, , % "ahk_id " . HLV
Return ErrorLevel
}
; ======================================================================================================================
; LV_EX_RedrawRows - Forces a list-view control to redraw a range of items.
; ======================================================================================================================
LV_EX_RedrawRows(HLV, First := 0, Last := "") {
; LVM_REDRAWITEMS = 0x1015 -> http://msdn.microsoft.com/en-us/library/bb761145(v=vs.85).aspx
If (First > 0) {
If (Last = "")
Last := First
}
Else {
First := LV_EX_GetTopIndex(HLV)
Last := First + LV_EX_GetRowsPerPage(HLV) - 1
}
SendMessage, 0x1015, % (First - 1), % (Last - 1), , % "ahk_id " . HLV
If (ErrorLevel)
Return DllCall("User32.dll\UpdateWindow", "Ptr", HLV, "UInt")
Return False
}
; ======================================================================================================================
; LV_EX_GetRowsPerPage - Calculates the number of items that can fit vertically in the visible area of a list-view
; control when in list or report view. Only fully visible items are counted.
; ======================================================================================================================
LV_EX_GetRowsPerPage(HLV) {
; LVM_GETCOUNTPERPAGE = 0x1028 -> http://msdn.microsoft.com/en-us/library/bb774917(v=vs.85).aspx
SendMessage, 0x1028, 0, 0, , % "ahk_id " . HLV
Return ErrorLevel
}
; ======================================================================================================================
; LV_EX_GetTopIndex - Retrieves the index of the topmost visible item when in list or report view.
; ======================================================================================================================
LV_EX_GetTopIndex(HLV) {
; LVM_GETTOPINDEX = 0x1027 -> http://msdn.microsoft.com/en-us/library/bb761087(v=vs.85).aspx
SendMessage, 0x1027, 0, 0, , % "ahk_id " . HLV
Return (ErrorLevel + 1)
}
; ======================================================================================================================
; LV_EX_SetGroup - Assigns a list-view item to an existing group.
; ======================================================================================================================
LV_EX_SetGroup(HLV, Row, GroupID) {
; LVM_SETITEMA = 0x1006 -> http://msdn.microsoft.com/en-us/library/bb761186(v=vs.85).aspx
Static OffGroupID := 28 + (A_PtrSize * 3)
LV_EX_LVITEM(LVITEM, 0x00000100, Row) ; LVIF_GROUPID
NumPut(GroupID, LVITEM, OffGroupID, "UPtr")
SendMessage, 0x1006, 0, % &LVITEM, , % "ahk_id " . HLV
Return ErrorLevel
}
; ======================================================================================================================
; ======================================================================================================================
; Function for internal use ============================================================================================
; ======================================================================================================================
; ======================================================================================================================
LV_EX_LVITEM(ByRef LVITEM, Mask := 0, Row := 1, Col := 1) {
Static LVITEMSize := 48 + (A_PtrSize * 3)
VarSetCapacity(LVITEM, LVITEMSize, 0)
NumPut(Mask, LVITEM, 0, "UInt"), NumPut(Row - 1, LVITEM, 4, "Int"), NumPut(Col - 1, LVITEM, 8, "Int")
}
; ----------------------------------------------------------------------------------------------------------------------
LV_EX_PWSTR(Str, ByRef WSTR) { ; ANSI to Unicode
VarSetCapacity(WSTR, StrPut(Str, "UTF-16") * 2, 0)
StrPut(Str, &WSTR, "UTF-16")
Return &WSTR
}
Code: Select all
;------------------------------------------------------------------------------
; Acc.ahk Standard Library
; by Sean
; Updated by jethrow:
; Modified ComObjEnwrap params from (9,pacc) --> (9,pacc,1)
; Changed ComObjUnwrap to ComObjValue in order to avoid AddRef (thanks fincs)
; Added Acc_GetRoleText & Acc_GetStateText
; Added additional functions - commented below
; Removed original Acc_Children function
; Added Acc_Error, Acc_ChildrenByRole, & Acc_Get functions
; last updated 10/25/2012
;------------------------------------------------------------------------------
Acc_Init()
{
Static h
If Not h
h:=DllCall("LoadLibrary","Str","oleacc","Ptr")
}
Acc_ObjectFromEvent(ByRef _idChild_, hWnd, idObject, idChild)
{
Acc_Init()
If DllCall("oleacc\AccessibleObjectFromEvent", "Ptr", hWnd, "UInt", idObject, "UInt", idChild, "Ptr*", pacc, "Ptr", VarSetCapacity(varChild,8+2*A_PtrSize,0)*0+&varChild)=0
Return ComObjEnwrap(9,pacc,1), _idChild_:=NumGet(varChild,8,"UInt")
}
Acc_ObjectFromPoint(ByRef _idChild_ = "", x = "", y = "")
{
Acc_Init()
If DllCall("oleacc\AccessibleObjectFromPoint", "Int64", x==""||y==""?0*DllCall("GetCursorPos","Int64*",pt)+pt:x&0xFFFFFFFF|y<<32, "Ptr*", pacc, "Ptr", VarSetCapacity(varChild,8+2*A_PtrSize,0)*0+&varChild)=0
Return ComObjEnwrap(9,pacc,1), _idChild_:=NumGet(varChild,8,"UInt")
}
Acc_ObjectFromWindow(hWnd, idObject = 0)
{
Acc_Init()
If DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject&=0xFFFFFFFF, "Ptr", -VarSetCapacity(IID,16)+NumPut(idObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81,NumPut(idObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0,IID,"Int64"),"Int64"), "Ptr*", pacc)=0
Return ComObjEnwrap(9,pacc,1)
}
Acc_WindowFromObject(pacc)
{
If DllCall("oleacc\WindowFromAccessibleObject", "Ptr", IsObject(pacc)?ComObjValue(pacc):pacc, "Ptr*", hWnd)=0
Return hWnd
}
Acc_GetRoleText(nRole)
{
nSize := DllCall("oleacc\GetRoleText", "Uint", nRole, "Ptr", 0, "Uint", 0)
VarSetCapacity(sRole, (A_IsUnicode?2:1)*nSize)
DllCall("oleacc\GetRoleText", "Uint", nRole, "str", sRole, "Uint", nSize+1)
Return sRole
}
Acc_GetStateText(nState)
{
nSize := DllCall("oleacc\GetStateText", "Uint", nState, "Ptr", 0, "Uint", 0)
VarSetCapacity(sState, (A_IsUnicode?2:1)*nSize)
DllCall("oleacc\GetStateText", "Uint", nState, "str", sState, "Uint", nSize+1)
Return sState
}
Acc_SetWinEventHook(eventMin, eventMax, pCallback)
{
Return DllCall("SetWinEventHook", "Uint", eventMin, "Uint", eventMax, "Uint", 0, "Ptr", pCallback, "Uint", 0, "Uint", 0, "Uint", 0)
}
Acc_UnhookWinEvent(hHook)
{
Return DllCall("UnhookWinEvent", "Ptr", hHook)
}
/* Win Events:
pCallback := RegisterCallback("WinEventProc")
WinEventProc(hHook, event, hWnd, idObject, idChild, eventThread, eventTime)
{
Critical
Acc := Acc_ObjectFromEvent(_idChild_, hWnd, idObject, idChild)
; Code Here:
}
*/
; Written by jethrow
Acc_Role(Acc, ChildId=0) {
try return ComObjType(Acc,"Name")="IAccessible"?Acc_GetRoleText(Acc.accRole(ChildId)):"invalid object"
}
Acc_State(Acc, ChildId=0) {
try return ComObjType(Acc,"Name")="IAccessible"?Acc_GetStateText(Acc.accState(ChildId)):"invalid object"
}
Acc_Location(Acc, ChildId=0, byref Position="") { ; adapted from Sean's code
try Acc.accLocation(ComObj(0x4003,&x:=0), ComObj(0x4003,&y:=0), ComObj(0x4003,&w:=0), ComObj(0x4003,&h:=0), ChildId)
catch
return
Position := "x" NumGet(x,0,"int") " y" NumGet(y,0,"int") " w" NumGet(w,0,"int") " h" NumGet(h,0,"int")
return {x:NumGet(x,0,"int"), y:NumGet(y,0,"int"), w:NumGet(w,0,"int"), h:NumGet(h,0,"int")}
}
Acc_Parent(Acc) {
try parent:=Acc.accParent
return parent?Acc_Query(parent):
}
Acc_Child(Acc, ChildId=0) {
try child:=Acc.accChild(ChildId)
return child?Acc_Query(child):
}
Acc_Query(Acc) { ; thanks Lexikos - www.autohotkey.com/forum/viewtopic.php?t=81731&p=509530#509530
try return ComObj(9, ComObjQuery(Acc,"{618736e0-3c3d-11cf-810c-00aa00389b71}"), 1)
}
Acc_Error(p="") {
static setting:=0
return p=""?setting:setting:=p
}
Acc_Children(Acc) {
if ComObjType(Acc,"Name") != "IAccessible"
ErrorLevel := "Invalid IAccessible Object"
else {
Acc_Init(), cChildren:=Acc.accChildCount, Children:=[]
if DllCall("oleacc\AccessibleChildren", "Ptr",ComObjValue(Acc), "Int",0, "Int",cChildren, "Ptr",VarSetCapacity(varChildren,cChildren*(8+2*A_PtrSize),0)*0+&varChildren, "Int*",cChildren)=0 {
Loop %cChildren%
i:=(A_Index-1)*(A_PtrSize*2+8)+8, child:=NumGet(varChildren,i), Children.Insert(NumGet(varChildren,i-8)=9?Acc_Query(child):child), NumGet(varChildren,i-8)=9?ObjRelease(child):
return Children.MaxIndex()?Children:
} else
ErrorLevel := "AccessibleChildren DllCall Failed"
}
if Acc_Error()
throw Exception(ErrorLevel,-1)
}
Acc_ChildrenByRole(Acc, Role) {
if ComObjType(Acc,"Name")!="IAccessible"
ErrorLevel := "Invalid IAccessible Object"
else {
Acc_Init(), cChildren:=Acc.accChildCount, Children:=[]
if DllCall("oleacc\AccessibleChildren", "Ptr",ComObjValue(Acc), "Int",0, "Int",cChildren, "Ptr",VarSetCapacity(varChildren,cChildren*(8+2*A_PtrSize),0)*0+&varChildren, "Int*",cChildren)=0 {
Loop %cChildren% {
i:=(A_Index-1)*(A_PtrSize*2+8)+8, child:=NumGet(varChildren,i)
if NumGet(varChildren,i-8)=9
AccChild:=Acc_Query(child), ObjRelease(child), Acc_Role(AccChild)=Role?Children.Insert(AccChild):
else
Acc_Role(Acc, child)=Role?Children.Insert(child):
}
return Children.MaxIndex()?Children:, ErrorLevel:=0
} else
ErrorLevel := "AccessibleChildren DllCall Failed"
}
if Acc_Error()
throw Exception(ErrorLevel,-1)
}
Acc_Get(Cmd, ChildPath="", ChildID=0, WinTitle="", WinText="", ExcludeTitle="", ExcludeText="") {
static properties := {Action:"DefaultAction", DoAction:"DoDefaultAction", Keyboard:"KeyboardShortcut"}
AccObj := IsObject(WinTitle)? WinTitle
: Acc_ObjectFromWindow( WinExist(WinTitle, WinText, ExcludeTitle, ExcludeText), 0 )
if ComObjType(AccObj, "Name") != "IAccessible"
ErrorLevel := "Could not access an IAccessible Object"
else {
StringReplace, ChildPath, ChildPath, _, %A_Space%, All
AccError:=Acc_Error(), Acc_Error(true)
Loop Parse, ChildPath, ., %A_Space%
try {
if A_LoopField is digit
Children:=Acc_Children(AccObj), m2:=A_LoopField ; mimic "m2" output in else-statement
else
RegExMatch(A_LoopField, "(\D*)(\d*)", m), Children:=Acc_ChildrenByRole(AccObj, m1), m2:=(m2?m2:1)
if Not Children.HasKey(m2)
throw
AccObj := Children[m2]
} catch {
ErrorLevel:="Cannot access ChildPath Item #" A_Index " -> " A_LoopField, Acc_Error(AccError)
if Acc_Error()
throw Exception("Cannot access ChildPath Item", -1, "Item #" A_Index " -> " A_LoopField)
return
}
Acc_Error(AccError)
StringReplace, Cmd, Cmd, %A_Space%, , All
properties.HasKey(Cmd)? Cmd:=properties[Cmd]:
try {
if (Cmd = "Location")
AccObj.accLocation(ComObj(0x4003,&x:=0), ComObj(0x4003,&y:=0), ComObj(0x4003,&w:=0), ComObj(0x4003,&h:=0), ChildId)
, ret_val := "x" NumGet(x,0,"int") " y" NumGet(y,0,"int") " w" NumGet(w,0,"int") " h" NumGet(h,0,"int")
else if (Cmd = "Object")
ret_val := AccObj
else if Cmd in Role,State
ret_val := Acc_%Cmd%(AccObj, ChildID+0)
else if Cmd in ChildCount,Selection,Focus
ret_val := AccObj["acc" Cmd]
else
ret_val := AccObj["acc" Cmd](ChildID+0)
} catch {
ErrorLevel := """" Cmd """ Cmd Not Implemented"
if Acc_Error()
throw Exception("Cmd Not Implemented", -1, Cmd)
return
}
return ret_val, ErrorLevel:=0
}
if Acc_Error()
throw Exception(ErrorLevel,-1)
}
Thanks!
-Treas