Acc-v2: MSAA Accessibility Library for AutoHotkey v2 With AccViewer

Before UI Automation there was Acc. Microsoft Active Accessibility, the older way programs expose their buttons and text to screen readers.

It still matters. Some programs expose more through Acc than through UIA, and Acc is often quicker to query.

Acc-v2 is Descolada’s AutoHotkey v2 library for it. Not a port of the v1 Acc.ahk you may remember, but a rewrite where every element is an object. 😊

AccViewer Shows You the Path to Any Element


Run Acc.ahk on its own and it opens AccViewer, an inspector built into the library.

Hover over any control and you see:

  • Its properties on the left: Name, Value, Role, State, Location
  • The Acc tree on the right, showing where it sits inside the window
  • The Acc path at the bottom, such as 4,1,4. Right-click to copy it

Include Acc.ahk in your own script and the viewer stays hidden. Call Acc.Viewer() if you want it back.

Elements Work Like Arrays


Get a window with Acc.ElementFromHandle(“ahk_exe notepad.exe”). From there the path you copied from AccViewer is just an index: oAcc[4,1,4].

Every element has a Length, you can loop over its children with a for loop, and the properties drop the old “acc” prefix. oEl.Name, oEl.Value, oEl.RoleText.

Do something with it: DoDefaultAction clicks a button or opens a menu, Value can be set on editable fields, Highlight draws a box around the element, and Dump or DumpAll give you the tree as text.

Find, Wait and React to Events


Paths break when a program updates. Conditions don’t:

  • FindElement({Name:”File”}) searches the tree for a match, with options for match mode, case and which match you want
  • WaitElementExist keeps looking until the element shows up or the timeout passes
  • RegisterWinEvent calls your function when Windows raises an accessibility event, such as focus changing or a menu opening

Chromium apps are handled too. ElementFromHandle switches on accessibility in Chrome and Edge before it reads them.

What’s in the Download


  • Lib\Acc.ahk: the library, with AccViewer built in
  • README.md: the reference for every method, property and constant
  • 9 examples: Notepad, caret position, focus events, VS Code line and column, page URL from a hovered link, conditions, and system events

The library is open source on GitHub. This copy is a snapshot of the repo so you have a version that matches these notes.

Requirements: AutoHotkey v2. Use #include Acc.ahk from the same folder, or #include <Acc> from your Lib folder.

Need the newer framework instead? See UIA-v2 by the same author.

Get Acc-v2


Acc-v2 is $3.00. Pick the price option that suits you. The higher ones help fund more videos and scripts.

When ControlGetText gives you nothing, try AccViewer before you give up on a program. ⚡

Joe

Comments are closed.