v2 Acc.ahk library Acc_Children() error
Posted: 18 Aug 2022, 02:12
Background: The v1 Acc.ahk library can interact with windows that are otherwise hard to control. Acc.ahk uses Microsoft Active Accessibility (MSAA). Lots of useful v1 scripts require Acc. There is work in progress on v2 Acc.ahk, but some issues remain and we're stuck.
Please help troubleshoot and solve the problem that v2 Acc's Acc_Children() errors in some cases where v1 does not.
Below are two small test scripts to reproduce the issue. Each script opens a File Explorer window and uses Acc to read role texts.
For the v2 script use Acc v2 version 2022-02-22 by eugenesv (this is also the most recent v2 Acc.ahk version)
viewtopic.php?p=433516#p433516
For the v1 script Acc v1 from
https://github.com/Ixiko/AHK-libs-and-classes-collection/blob/master/libs/a-f/ACC.ahk
v2 code (errors)
v1 code (working)
(Note that File Explorer is just a simple example here, the same issue happens in other apps too.)
Please help troubleshoot and solve the problem that v2 Acc's Acc_Children() errors in some cases where v1 does not.
Below are two small test scripts to reproduce the issue. Each script opens a File Explorer window and uses Acc to read role texts.
For the v2 script use Acc v2 version 2022-02-22 by eugenesv (this is also the most recent v2 Acc.ahk version)
viewtopic.php?p=433516#p433516
For the v1 script Acc v1 from
https://github.com/Ixiko/AHK-libs-and-classes-collection/blob/master/libs/a-f/ACC.ahk
v2 code (errors)
Code: Select all
#Include Acc.ahk2
Run "C:\" ; open File Explorer to C:\ for Acc test
Sleep(500)
If !WinActive("C:\ ahk_class CabinetWClass")
ExitApp
A := Acc_ObjectFromWindow(hWnd := WinExist("A"), 0x0) ; get root Acc object
MsgBox Acc_GetRoleText(A.accRole(0)) ; "window"
C := Acc_Children(A) ; get level1 children
MsgBox Acc_GetRoleText(C[1].accRole(0)) ; "menu bar"
CC := Acc_Children(C[1]) ; (fail to) get level2 children of level1 node1
; "Error in #include Acc.ahk2", "An exception was thrown.", "Specifically: 0xc0000005"
Code: Select all
#Include Acc.ahk
Run C:\ ; open File Explorer to C:\ for Acc test
Sleep 500
If !WinActive("C:\ ahk_class CabinetWClass")
ExitApp
A := Acc_ObjectFromWindow(hWnd := WinExist("A"), 0x0) ; get root Acc object
MsgBox % Acc_GetRoleText(A.accRole(0)) ; "window"
C := Acc_Children(A) ; get level1 children
MsgBox % Acc_GetRoleText(C[1].accRole(0)) ; "menu bar"
CC := Acc_Children(C[1]) ; get level2 children of level1 node1
MsgBox % Acc_GetRoleText(CC[1].accRole(0)) ; "menu item"