Acc (MSAA) - Text Without Needing Cursor Position? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Posts: 1449
Joined: 19 Dec 2013, 11:16
Location: USA

Acc (MSAA) - Text Without Needing Cursor Position?

31 Jan 2017, 09:34

I want to use the Acc library to retrieve text from a specific section in the statusbar of an application. I am trying to understand how the AccViewer script (linked below) works, and extracting the parts that I need.

So far I'm able to get the text, but only if the mouse cursor is positioned above it. Is there a way to define the exact position of the text without needing to use the current mouse coordinates? I see in the AccViewer script there's mention of the "path" -- Can that be used to do what I need?

Here's the script I have which requires using the mouse coordinates:

Code: Select all

#SingleInstance, Force

    Acc := Acc_ObjectFromPoint(ChildId)
    MsgBox, % Acc.accName(ChildId)

Acc_Init() {
    Static h

    If (!h) {
        h := DllCall("LoadLibrary", "Str", "Oleacc.dll", "Ptr")

Acc_ObjectFromPoint(ByRef _idChild_ := "", x := "", y := "") {

    If (DllCall("Oleacc.dll\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_WindowFromObject(pacc) {
    If (DllCall("Oleacc.dll\WindowFromAccessibleObject", "Ptr", IsObject(pacc) ? ComObjValue(pacc) : pacc, "Ptr*", hWnd) = 0) {
        return hWnd
FYI -- I am having to use the Accessibility library because the application is using the .NET windows forms that AutoHotkey can't read.

Acc.ahk ... es/Acc.ahk

AccViewer.ahk ... Viewer.ahk
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
User avatar
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Acc (MSAA) - Text Without Needing Cursor Position?  Topic is solved

31 Jan 2017, 09:51

This should do it! Best of luck.

Code: Select all

q:: ;test - get status bar text
;e.g. Notepad (Windows 7)
ControlGet, hCtl, Hwnd, , msctls_statusbar321, A
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hCtl)
vText := oAcc.accName(2) ;e.g. change '2' to '3' to get the 3rd part
oAcc := ""
MsgBox % "[" vText "]"
Acc_ObjectFromPoint(ByRef _idChild_ = "", x = "", y = "")
gets the object under the cursor if x and y are not specified,
otherwise it gets the object under the pixel specified.

If I want to specify a window/control I use:
Acc_ObjectFromWindow or Acc_Get.
To refer to the exact object/child item you want,
you will need to do things like get the nth child once or repeatedly,
or use Acc_Get specifying a path as a parameter.
The required path is often the same as what AccViewer shows,
sometimes needing additional items at the beginning.

From my recollection, StatusbarGetText only works if the ClassNN
of the control is msctls_statusbar321.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Stuff n Things
Posts: 18
Joined: 23 Jan 2017, 12:42

Re: Acc (MSAA) - Text Without Needing Cursor Position?

31 Jan 2017, 10:14

It should be possible to use the AccViewer.ahk script get the "path" of the object you want, then pull the text you need.

Obj := Acc_Get(Cmd, ChildPath="", ChildID=0, WinTitle="", WinText="", ExcludeTitle="", ExcludeText="") **As referenced in AccViewer.ahk**
Text := Obj.accName(ChildID) **As referenced in AccViewer.ahk**

Example Code below:

Code: Select all

ObjList := Acc_Get("Object", "", 0, "Search Tool")
Name := ObjList.accName(ChildID)

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], jackn11, jasc2v8, LeroyMcCheeks and 32 guests