jeeswg's Acc tutorial (Microsoft Active Accessibility) (MSAA)
Posted: 28 Nov 2017, 03:54
==================================================
Microsoft Active Accessibility (MSAA) (Acc)
- You can use the Acc functions, in the Acc.ahk library, to get information about windows/controls/GUI elements, and to, in some ways, interact with them.
- There is also a key script called AccViewer, a window inspector, which demonstrates much of the info that the Acc functions can retrieve.
GET WINDOW INFO:
- I use AccViewer as a window spy, to get information about windows/controls/GUI elements. E.g. text, positions, focused/selected/hidden states.
- 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.
- One thing that AccViewer doesn't currently show is the GUI element state (e.g. focused), see AccViewer Basic which does. E.g. the state can tell you which web browser is focused.
GET WINDOW INFO (ACC PATH):
- Another thing to mention is the Acc path.
- An Acc path is a list of numbers, e.g. '1.2.3'. If you specify a window's/control's hWnd and '1.2.3', then you start at the GUI element corresponding to the hWnd, you get its 1st child, then that element's 2nd child, then that element's 3rd child, you have then specified a GUI element relative to an hWnd.
- You can pass an hWnd and an Acc path to the Acc_Get function, to access a specific GUI element.
- AccViewer shows an Acc path in the status bar, this is not always the exact path that Acc_Get needs. However, you can use my JEE_AccGetTextAll function, this should give you the correct path. The JEE_AccGetTextAll function can be used to get text and ID information for all the GUI elements in a window/control.
SET WINDOW INFO/INTERACT WITH WINDOW:
- Acc provides an accDoDefaultAction method, where available, this is usually equivalent to clicking on a GUI element/control.
- The accSelect method can be used to change the focused/selected items in a control e.g. a listview control.
- For *some* but not all GUI elements, you can set the element's value by specifying the text via accValue.
- Although I haven't been able to get Acc to right-click a GUI element, I have been able to use Acc to get the position of a GUI element, and use non-Acc techniques to perform a right-click at that position.
CONTROLS:
- Sometimes you do not need Acc. I.e. instead of referring to GUI elements, you can just refer to controls.
- Any information that can be retrieved via AutoHotkey's built-in window spy, can be retrieved using built-in AutoHotkey commands/functions e.g. the ControlXXX/WinXXX commands.
- To use AutoHotkey's built-in window spy, right-click the tray icon, click 'Open', and go to 'File, Window Spy'.
==================================================
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
[JEE_AccGetPath: get Acc path for GUI element]
[e.g. element under cursor, element at a specific point, any element]
How to get the full ACC path for control on cursor? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=56470&p=254902#p254902
==================================================
REFERENCE LISTS
[list of methods (new/old versions of page)]
IAccessible interface (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/dd318466(v=vs.85).aspx
IAccessible interface (Windows)
https://web.archive.org/web/20161224102522/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
==================================================
LIST OF METHODS
Note: these methods apply to any programming language, whereas the Acc_XXX functions and AccViewer script are custom code written by AutoHotkey users.
- accChild: get an object for one of a GUI element's child elements (often fails, instead, consider Acc_Children, which uses oleacc\AccessibleChildren, which appears to work always/almost always)
- accChildCount: get a number indicating how many child elements a GUI element has
- accDefaultAction: get text describing what the default action does (e.g. 'Execute', often equivalent to clicking it)
- accDescription
- accDoDefaultAction: perform the element's default action (often equivalent to clicking it)
- accFocus: get a number indicating the focused item index, e.g. in a listview (note: use accSelect to focus an item)
- accHelp
- accHelpTopic
- accHitTest
- accKeyboardShortcut
- accLocation: can be used to output ByRef a GUI element's coordinates
- accName: get the text of/text relating to a GUI element
- accNavigate: (deprecated)
- accParent: get an object for a GUI element's parent element
- accRole: get a number indicating a GUI element's role, e.g. title bar, push button
- accSelect: change the focused/selected items, e.g. in a listview (in theory, this could focus an element, like AHK's ControlFocus focuses a control, but it often fails)
- accSelection: get a number indicating the selected item index, e.g. in a listview (or an object indicating the selected item indexes) (note: use accSelect to select items)
- accState: get a number indicating the focused/selected state etc
- accValue: get the text of/text relating to a GUI element
note the distinction:
accDefaultAction [no 'do']
accDoDefaultAction [contains 'do']
See also:
IAccessible interface (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/dd318466(v=vs.85).aspx
==================================================
THE ACC_GET FUNCTION'S 'CMD' PARAMETER
Some notes on the Acc_Get function's 'Cmd' parameter:
pass 'Object' to return an Acc object
or pass the method name minus 'acc' to invoke a method:
e.g. pass 'Name' to invoke accName
e.g. pass 'Value' to invoke accValue
(note: see the list of accXXX methods above)
or pass one of these abbreviations to invoke the corresponding method:
Action (accDefaultAction)
DoAction (accDoDefaultAction)
Keyboard (accKeyboardShortcut)
note: Acc_Get uses some custom handling for these methods: accLocation/accRole/accState
==================================================
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
Introduction to Microsoft Active Accessibility - CodeProject
https://www.codeproject.com/Articles/18290/Introduction-to-Microsoft-Active-Accessibility
[original Acc threads]
Accessibility Standard Library - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/22058-accessibility-standard-library/
Acc Library [AHK_L] (updated 09/27/2012) - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/77303-acc-library-ahk-l-updated-09272012/
Accessible Info Viewer - Alpha Release (2012-09-20) - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/77888-accessible-info-viewer-alpha-release-2012-09-20/
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
- How to open specific dialogue box in MS Excel on pressing a HotKey?
- Sending keystrokes to a background process (hidden)
- IE COM fire click event
- How to get the full ACC path for control on cursor?
- Need Help in using ACC library
- AccessibleObjectFromWindow does not execute method accFocus in Firefox
- Select a line from a menu with the text...?
Threads by other people involving Acc:
- Firefox close tab if there is no more history
Microsoft Active Accessibility (MSAA) (Acc)
- You can use the Acc functions, in the Acc.ahk library, to get information about windows/controls/GUI elements, and to, in some ways, interact with them.
- There is also a key script called AccViewer, a window inspector, which demonstrates much of the info that the Acc functions can retrieve.
GET WINDOW INFO:
- I use AccViewer as a window spy, to get information about windows/controls/GUI elements. E.g. text, positions, focused/selected/hidden states.
- 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.
- One thing that AccViewer doesn't currently show is the GUI element state (e.g. focused), see AccViewer Basic which does. E.g. the state can tell you which web browser is focused.
GET WINDOW INFO (ACC PATH):
- Another thing to mention is the Acc path.
- An Acc path is a list of numbers, e.g. '1.2.3'. If you specify a window's/control's hWnd and '1.2.3', then you start at the GUI element corresponding to the hWnd, you get its 1st child, then that element's 2nd child, then that element's 3rd child, you have then specified a GUI element relative to an hWnd.
- You can pass an hWnd and an Acc path to the Acc_Get function, to access a specific GUI element.
- AccViewer shows an Acc path in the status bar, this is not always the exact path that Acc_Get needs. However, you can use my JEE_AccGetTextAll function, this should give you the correct path. The JEE_AccGetTextAll function can be used to get text and ID information for all the GUI elements in a window/control.
SET WINDOW INFO/INTERACT WITH WINDOW:
- Acc provides an accDoDefaultAction method, where available, this is usually equivalent to clicking on a GUI element/control.
- The accSelect method can be used to change the focused/selected items in a control e.g. a listview control.
- For *some* but not all GUI elements, you can set the element's value by specifying the text via accValue.
- Although I haven't been able to get Acc to right-click a GUI element, I have been able to use Acc to get the position of a GUI element, and use non-Acc techniques to perform a right-click at that position.
CONTROLS:
- Sometimes you do not need Acc. I.e. instead of referring to GUI elements, you can just refer to controls.
- Any information that can be retrieved via AutoHotkey's built-in window spy, can be retrieved using built-in AutoHotkey commands/functions e.g. the ControlXXX/WinXXX commands.
- To use AutoHotkey's built-in window spy, right-click the tray icon, click 'Open', and go to 'File, Window Spy'.
==================================================
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
[JEE_AccGetPath: get Acc path for GUI element]
[e.g. element under cursor, element at a specific point, any element]
How to get the full ACC path for control on cursor? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=56470&p=254902#p254902
==================================================
REFERENCE LISTS
[list of methods (new/old versions of page)]
IAccessible interface (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/dd318466(v=vs.85).aspx
IAccessible interface (Windows)
https://web.archive.org/web/20161224102522/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
==================================================
LIST OF METHODS
Note: these methods apply to any programming language, whereas the Acc_XXX functions and AccViewer script are custom code written by AutoHotkey users.
- accChild: get an object for one of a GUI element's child elements (often fails, instead, consider Acc_Children, which uses oleacc\AccessibleChildren, which appears to work always/almost always)
- accChildCount: get a number indicating how many child elements a GUI element has
- accDefaultAction: get text describing what the default action does (e.g. 'Execute', often equivalent to clicking it)
- accDescription
- accDoDefaultAction: perform the element's default action (often equivalent to clicking it)
- accFocus: get a number indicating the focused item index, e.g. in a listview (note: use accSelect to focus an item)
- accHelp
- accHelpTopic
- accHitTest
- accKeyboardShortcut
- accLocation: can be used to output ByRef a GUI element's coordinates
- accName: get the text of/text relating to a GUI element
- accNavigate: (deprecated)
- accParent: get an object for a GUI element's parent element
- accRole: get a number indicating a GUI element's role, e.g. title bar, push button
- accSelect: change the focused/selected items, e.g. in a listview (in theory, this could focus an element, like AHK's ControlFocus focuses a control, but it often fails)
- accSelection: get a number indicating the selected item index, e.g. in a listview (or an object indicating the selected item indexes) (note: use accSelect to select items)
- accState: get a number indicating the focused/selected state etc
- accValue: get the text of/text relating to a GUI element
note the distinction:
accDefaultAction [no 'do']
accDoDefaultAction [contains 'do']
See also:
IAccessible interface (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/dd318466(v=vs.85).aspx
==================================================
THE ACC_GET FUNCTION'S 'CMD' PARAMETER
Some notes on the Acc_Get function's 'Cmd' parameter:
pass 'Object' to return an Acc object
or pass the method name minus 'acc' to invoke a method:
e.g. pass 'Name' to invoke accName
e.g. pass 'Value' to invoke accValue
(note: see the list of accXXX methods above)
or pass one of these abbreviations to invoke the corresponding method:
Action (accDefaultAction)
DoAction (accDoDefaultAction)
Keyboard (accKeyboardShortcut)
note: Acc_Get uses some custom handling for these methods: accLocation/accRole/accState
==================================================
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
Introduction to Microsoft Active Accessibility - CodeProject
https://www.codeproject.com/Articles/18290/Introduction-to-Microsoft-Active-Accessibility
[original Acc threads]
Accessibility Standard Library - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/22058-accessibility-standard-library/
Acc Library [AHK_L] (updated 09/27/2012) - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/77303-acc-library-ahk-l-updated-09272012/
Accessible Info Viewer - Alpha Release (2012-09-20) - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/77888-accessible-info-viewer-alpha-release-2012-09-20/
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
- How to open specific dialogue box in MS Excel on pressing a HotKey?
- Sending keystrokes to a background process (hidden)
- IE COM fire click event
- How to get the full ACC path for control on cursor?
- Need Help in using ACC library
- AccessibleObjectFromWindow does not execute method accFocus in Firefox
- Select a line from a menu with the text...?
Threads by other people involving Acc:
- Firefox close tab if there is no more history