This quick fix works, although it breaks the script for lower level text.
Code: Select all
;before:
oAcc := oAcc.accParent
;after:
Loop, 2
oAcc := oAcc.accParent
The problem is that there isn't an easy way to decide how many levels up to check text, as mentioned here:
How to get the full ACC path for control on cursor? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=56470
[EDIT:] Here's an improved function that can check further up the hierarchy until a match is found.
Code: Select all
q:: ;acc get text under cursor
;first available name and value (may be from different elements):
MsgBox, % JEE_AccGetTextUnderCursor("n") "`r`n`r`n" JEE_AccGetTextUnderCursor("v")
JEE_AccGetTextUnderCursor("v", oAcc1, vChildID1)
JEE_AccGetTextUnderCursor("n", oAcc2, vChildID2)
;name/value from element with first available value:
MsgBox, % oAcc1.accName(vChildID1) "`r`n`r`n" oAcc1.accValue(vChildID1)
;name/value from element with first available name:
MsgBox, % oAcc2.accName(vChildID2) "`r`n`r`n" oAcc2.accValue(vChildID2)
return
;[Acc functions]
;Acc library (MSAA) and AccViewer download links - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201
JEE_AccGetTextUnderCursor(vOpt:="v", ByRef oAcc2:="", ByRef vChildID2:=0, vRecurseDepth:=3)
{
local
vType := InStr(vOpt, "v") ? "accValue" : "accName"
oAcc := Acc_ObjectFromPoint(vChildID)
vText := ""
try vText := oAcc[vType](vChildID)
if (vText = "") && vChildID
try vText := oAcc[vType](0)
if (vText = "")
{
VarSetCapacity(RECT1, 16)
VarSetCapacity(RECT2, 16)
VarSetCapacity(RECT3, 16)
oRect := Acc_Location(oAcc, vChildID)
DllCall("user32\SetRect", Ptr,&RECT1, Int,oRect.x, Int,oRect.y, Int,oRect.x+oRect.w, Int,oRect.y+oRect.h)
vIsMatch := 0
Loop, % vRecurseDepth - 1
{
oAcc := oAcc.accParent
for _, oChild in Acc_Children(oAcc)
{
vText := ""
oRect := Acc_Location(oChild)
DllCall("user32\SetRect", Ptr,&RECT2, Int,oRect.x, Int,oRect.y, Int,oRect.x+oRect.w, Int,oRect.y+oRect.h)
if !DllCall("user32\IntersectRect", Ptr,&RECT3, Ptr,&RECT1, Ptr,&RECT2)
continue
try vText := oChild[vType](0)
if (vText = "")
continue
oAcc2 := oChild
vIsMatch := 1
break
}
if vIsMatch
break
}
}
else
oAcc2 := oAcc
vChildID2 := vChildID
oAcc := oChild := ""
return vText
}