jeeswg's Acc tutorial (Microsoft Active Accessibility) (MSAA)

Helpful script writing tricks and HowTo's
User avatar
jeeswg
Posts: 4504
Joined: 19 Dec 2016, 01:58
Location: UK

jeeswg's Acc tutorial (Microsoft Active Accessibility) (MSAA)

28 Nov 2017, 03:54

==================================================

Microsoft Active Accessibility (MSAA) (Acc)

GET WINDOW INFO:
- I use AccViewer as a window spy, to get information about windows/controls/GUI elements.
- One thing that AccViewer doesn't currently show is the GUI element state, see AccViewer Basic which does.
- Any information that can be retrieved via AccViewer, can be retrieved using the Acc functions (Acc library).
- The AccViewer Basic script demonstrates how to use the Acc functions.

SET WINDOW INFO/INTERACT WITH WINDOW:
- Acc provides an accDoDefaultAction method, where available, this is usually equivalent to double-clicking on a GUI element/control.
- The accSelect method can be used to change the focus/selection.
- For *some* but not all GUI elements, you can set the value by specifying the text via accValue.

==================================================

SCRIPTS / FUNCTIONS

Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

[examples of how to get information from a window via Acc]
AccViewer Basic - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=32039

[JEE_AccGetTextAll: a function to get text and ID information for all the GUI elements in a window/control]
GUIs via DllCall: get/set internal/external control text - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=40514
Acc: get text from all window/control elements - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=40615

==================================================

REFERENCE LISTS

[list of methods]
IAccessible interface (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/dd318466(v=vs.85).aspx

[role constants (describe the type of a GUI element)]
AccViewer Basic - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=32039&p=167451#p167451

[state constants (describe the state of a GUI element)]
AccViewer Basic - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=32039&p=177601#p177601

[selection constants for use with accSelect]
SELFLAG Constants (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/dd373634(v=vs.85).aspx

==================================================

FURTHER LINKS AND EXAMPLE SCRIPTS

[introductions]
Microsoft Active Accessibility - Wikipedia
https://en.wikipedia.org/wiki/Microsoft_Active_Accessibility
Microsoft Active Accessibility (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/dd373592(v=vs.85).aspx

Threads where I use Acc_Get:
- Get the URL of the current (active) browser tab
- Get text from status bar
- Unable to detect Checkbox control using Windows Spy
- GUI COMMANDS: COMPLETE RETHINK
- Hotkey to sort images by Rating/Descending
- Internet Explorer: move tab to new window
- obs studio start and record
- Acc library (MSAA) and AccViewer download links
- Internet Explorer Save Open Cancel Popup
- set text/state of listbox/listview items via Acc?
- AccViewer crashing, Acc.ahk failing (invoke items, retrieve text, IE/Explorer/VLC)
- is it possible to write a script that opens specific chrome or firefox tabs
- Windows Update: detect if important updates available
- Firefox/Chrome, get tab names/focus tab
- Move mouse to taskbar to use AeroPeek
- Acc (MSAA) - Text Without Needing Cursor Position?
- WinGetText and ControlGetText not working on certain windows
- ResetArray() , ExtractURLDomain(), GetChromeURL()
- notepad get/set path (get/set text file path)
- Resizing the preview pane of Windows Explorer
- Acc / AccViewer / iWB2 Learner / Anchor conversion attempts
- IE Com Save Dialog - Auto Save using ACC
- ungettable text (Character Map/Excel/WordPad)
- Chrome update, now winkill not working
- Select text from prompt and select the proper option
- Getting position and size of the scroll bar
- jeeswg's Notepad tutorial
- Close a Window - How
- To Scroll the Bar with Arrow Keys
- Detect if classNN is scrollable
- Selecting a tab in another program
- Grabbing scrollbar control or location
- Explorer column interaction (get/set: which appear, width, ascending/descending order)
- Windows Explorer folder positions and scrolling
- Add "https://" in URL if specific error page is displayed on Google Chrome
- Internet Explorer: activate tab
- ACC.AHK - Get IAccessible for Context menu
- Script idea for an expert: typing in list view
- script to full screen YouTube videos
- Hotkey Control Partially Works
- Explorer window interaction (folder windows/Desktop, file/folder enumeration/selection/navigation/creation)
- Is it possible to get coordinates of selected item in TreeView (TreeViewWndClass1) control ?
- How to click on the control position?
- set value to Acc object children?
- Check if a box is checked in an other program
- Using COM to manipulate Microsoft Word's Navigation task pane
- ControlClick to click on X of window
- ControlSend command to send the problem
- active accessibility get value
- active accessibility click selectable
- Shortage for few auto excel operations ?
- Spotify PostMessage Library
- Assistance with Windows Text via Acc Library
- Clicks on the Notification Area of TaskBar
- Help with IAccessible objects
- how to click the first item in a listview?
- GUIs via DllCall: get/set internal/external control text
- Pin to taskbar in Windows 10
- Acc: get text from all window/control elements
- how to know if windows media player is playing or not?
- Firefox : toggle on/off sidebar - HELP
- Doubleclick On Selected Treeview Item
- Help to find the active tab number in Firefox
- Screen position of items in listview?
- possible to get information from external treeview?
- Open/Save dialogue in IE
Last edited by jeeswg on 16 May 2018, 20:57, edited 9 times in total.
User avatar
jeeswg
Posts: 4504
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's Acc tutorial (initial content)

28 Nov 2017, 04:19

[RESERVED]
neogna2
Posts: 21
Joined: 15 Sep 2016, 15:44

Re: jeeswg's Acc tutorial (Microsoft Active Accessibility) (MSAA)

27 Apr 2018, 03:26

Do you know how to use Acc to check if an element has keyboard focus? Specifically I want to check if the URL bar in Firefox and Chrome has keyboard focus or not. This MSDN page seems relevant, but I couldn't figure out the syntax for it in AutoHotkey with Acc.ahk

edit: fixed URL

edit2: solved it after a second look at the source of your Acc Viewer Basic. We check if an object ís focused with

Code: [Select all] [Download] GeSHi © Codebox Plus

if (oAcc.accFocus = "0")

I was confused by the fact that accFocus returns 0 if the object has focus and nothing if the object does not have focus.

I adapted some of your code into two functions that return 1 if the URL bar has focus

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
jeeswg
Posts: 4504
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's Acc tutorial (Microsoft Active Accessibility) (MSAA)

27 Apr 2018, 06:59

- Take a look at accState:

Code: [Select all] [Download] GeSHi © Codebox Plus

vAccStateNum := oAcc.accState(vChildId)
vAccStateNumHex := Format("0x{:X}", vAccStateNum)
- There's an example here.
Help to find the active tab number in Firefox - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=45626&p=206156#p206156
- Also, check the link to state constants above.

- Re. accFocus (and accSelection):
- I hadn't looked too closely at accFocus or accSelection before, they appear to work with certain controls, e.g. listview controls, to report which items are focused/selected.
- accFocus returns the index of the focused item.
- accSelection returns the index of the selected item, or an object if multiple items are selected.
- I had trouble trying to retrieve the indexes from an object, but there was a useful link re. accSelection here (thanks just me and lexikos):
- I'll improve my AccViewer Basic script with my new-found knowledge.
[Solved] IAccessible - Accessible Objects - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=11928&p=62811#p62811

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by jeeswg on 28 Apr 2018, 17:22, edited 1 time in total.
neogna2
Posts: 21
Joined: 15 Sep 2016, 15:44

Re: jeeswg's Acc tutorial (Microsoft Active Accessibility) (MSAA)

27 Apr 2018, 07:26

Thanks for the reply

jeeswg wrote:- accFocus returns the index of the focused item.

Ok, that explains why it returns 0 when the URL bar has focus.
User avatar
jeeswg
Posts: 4504
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's Acc tutorial (Microsoft Active Accessibility) (MSAA)

28 Apr 2018, 17:48

I've improved AccViewer Basic to better support accSelection (multiple items selected) and accState (provide friendly text for all of an item's state flags).
neogna2
Posts: 21
Joined: 15 Sep 2016, 15:44

Re: jeeswg's Acc tutorial (Microsoft Active Accessibility) (MSAA)

01 May 2018, 08:30

jeeswg wrote:I've improved AccViewer Basic to better support accSelection (multiple items selected) and accState (provide friendly text for all of an item's state flags).

Useful! On small thing is that the Name contents placed first in the tooltip can be very long for example when viewing the text pane of Notepad++. In that case the other tooltip variables are pushed out of view below the screen. I worked around that with this change to your script.

Code: [Select all] [Download] GeSHi © Codebox Plus

vAccNameShort := SubStr(vAccName, 1, 200)
vOutput = ;continuation section
(
Name: %vAccNameShort%
User avatar
jeeswg
Posts: 4504
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's Acc tutorial (Microsoft Active Accessibility) (MSAA)

01 May 2018, 08:53

I'd previously added a fix for other variables to AccViewer Basic, I've updated the script to add vAccName to the list:

Code: [Select all] [Download] GeSHi © Codebox Plus

;before:
vList := "vWinText,vAccValue"
;after:
vList := "vWinText,vAccName,vAccValue"
DRocks
Posts: 23
Joined: 08 May 2018, 10:20

Re: jeeswg's Acc tutorial (Microsoft Active Accessibility) (MSAA)

28 May 2018, 04:29

hi jeeswg

I have been reading a couple of your topics so thanks so much for the help you provide here.
Are you interested in anything like making short videos about some of the most important discoveries you've explained by text? It is a suggestion that runs my mind as I write because I think it would make your content be even more educationnal. Just a thought like that :)

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 6 guests