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

Helpful script writing tricks and HowTo's
User avatar
jeeswg
Posts: 5164
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
Last edited by jeeswg on 27 Jul 2018, 07:44, edited 10 times in total.
User avatar
jeeswg
Posts: 5164
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's Acc tutorial (initial content)

28 Nov 2017, 04:19

[RESERVED]
neogna2
Posts: 23
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

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

FirefoxUrlBarFocused(hWnd)
{
  vAccPath := "application.tool_bar3.combo_box1.editable_text"
  ;vAccPath := "4.27.4.2"
  oAcc := Acc_Get("Object", vAccPath, 0, "ahk_id " hWnd)
  Return oAcc.accFocus = "0" ? 1 : 0
}

ChromeUrlBarFocused(hWnd)
{
  vAccPath := "pane.client.client2.client2.client.grouping.editable_text"
  ;vAccPath := "4.1.2.2.3.5.2"
  oAcc := Acc_Get("Object", vAccPath, 0, "ahk_id " hWnd)
  Return oAcc.accFocus = "0" ? 1 : 0
}
User avatar
jeeswg
Posts: 5164
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

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 ... 56#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 ... 811#p62811

Code: Select all

q:: ;Acc - get the index of the focused item / index(es) of the selected item(s)
;e.g. test this on a listview control
WinGet, hWnd, ID, A
ControlGetFocus, vCtlClassNN, % "ahk_id " hWnd
ControlGet, hCtl, Hwnd,, % vCtlClassNN, % "ahk_id " hWnd
oAcc := Acc_ObjectFromWindow(hCtl)
vFoc := oAcc.accFocus ;gets index of focused item
vSel := oAcc.accSelection ;if one item selected, gets index, if multiple items selected, gets indexes as object

if IsObject(vSel)
{
	oSel := vSel, vSel := ""
	while oSel.Next(vValue, vType)
		vSel .= (A_Index=1?"":",") vValue
	oSel := ""
}

MsgBox, % "foc: " vFoc "`r`n" "sel: " vSel
oAcc := ""
return
Last edited by jeeswg on 28 Apr 2018, 17:22, edited 1 time in total.
neogna2
Posts: 23
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: 5164
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: 23
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

vAccNameShort := SubStr(vAccName, 1, 200)
vOutput = ;continuation section
(
Name: %vAccNameShort%
User avatar
jeeswg
Posts: 5164
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

;before:
vList := "vWinText,vAccValue"
;after:
vList := "vWinText,vAccName,vAccValue"
DRocks
Posts: 148
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 :)
Nate32
Posts: 1
Joined: 08 Jul 2018, 01:02

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

08 Jul 2018, 09:53

merci beaucoup d'avoir pris la peine de faire tout ça. Thank you

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 4 guests