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

Helpful script writing tricks and HowTo's
julesverne
Posts: 42
Joined: 18 Apr 2017, 14:39
Contact:

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

Post by julesverne » 03 Aug 2019, 13:10

I'm not sure how, but I figured it out, it's working. I think the biggest hurdle I faced was where you were coming up with the ACCpath numbers (using your Notepad example I was finally able to understand). A couple things I couldn't figure out still was how does a child path work into the function below, in addition what is parameter 3 and is it always 0?

Code: Select all

oAcc := Acc_Get("Object", "1.30", 0, "ahk_id " hCtl)
Also, thanks again! Acc Rules!!

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

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

Post by jeeswg » 03 Aug 2019, 13:45

- Acc_Get's ChildID parameter is sometimes used to specify a subitem, e.g. 0 for the listview, a positive integer for a specific listview item.
- I use JEE_AccGetTextAll to determine Acc_Get's ChildPath parameter, it may also be possible to derive this via AccViewer's status bar. Each number in the path refers to the nth child of an object.
- Btw do always try AHK's window spy first, some things can be done via ClassNNs and ControlGetText/other ControlXXX commands/functions. [EDIT: I've added some text re. the Acc path and re. controls to the first post of this thread.]
Last edited by jeeswg on 16 Aug 2019, 13:17, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

blue83
Posts: 157
Joined: 11 Apr 2018, 06:38

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

Post by blue83 » 06 Aug 2019, 02:56

Hi jeeswg,

I can not get "JEE_AccGetTextAll" to work.

Can you give me an example of a script with some app.

Dont know what to include, how to do it in a way that at the end MsgBox show me what it should.

Thank you.

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

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

Post by jeeswg » 10 Aug 2019, 18:06

Some pointers on using JEE_AccGetTextAll.
Note: it can be quite slow, because there may be a lot of GUI elements to loop through.
I generally use it for diagnostic purposes to get info on a window, and typically use Acc_Get in everyday scripts.

Code: Select all

;add an #Include line e.g.:
;#Include Acc.ahk
;#Include C:\MyDir\Acc.ahk

;or don't use #Include, but instead:
;copy Acc.ahk to an appropriate Lib folder:
;Functions - Definition & Usage | AutoHotkey
;https://www.autohotkey.com/docs/Functions.htm#lib
;%A_ScriptDir%\Lib\  ; Local library - requires [v1.0.90+].
;%A_MyDocuments%\AutoHotkey\Lib\  ; User library.
;directory-of-the-currently-running-AutoHotkey.exe\Lib\  ; Standard library.

q:: ;get text and Acc paths for GUI elements
WinGet, hWnd, ID, A
Clipboard := JEE_AccGetTextAll(hWnd, "`r`n")
MsgBox, % "done"
return

;paste the 'JEE_AccGetTextAll' function somewhere in the script
;(it can be above or below the code where it's used)
;available at these 2 links:
;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_AccGetTextAll(...)
;{
;...
;}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

blue83
Posts: 157
Joined: 11 Apr 2018, 06:38

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

Post by blue83 » 12 Aug 2019, 01:58

Hi jeeswg,

Yes ofcourse, you just open my eyes, I was so close to final result.

Thank you on clarification.

AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

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

Post by AHKStudent » 09 Nov 2019, 18:01

"accLocation: can be used to output ByRef a GUI element's coordinates"

Hi Jeeswg

Do you have a sample of this? gsvidip.accLocation(0) (what to place as parameters instead of the 0?)

Thanks

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

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

Post by jeeswg » 09 Nov 2019, 18:16

From Acc.ahk:

Code: Select all

Acc_Location(Acc, ChildId=0, byref Position="") { ; adapted from Sean's code
	try Acc.accLocation(ComObj(0x4003,&x:=0), ComObj(0x4003,&y:=0), ComObj(0x4003,&w:=0), ComObj(0x4003,&h:=0), ChildId)
	catch
		return
	Position := "x" NumGet(x,0,"int") " y" NumGet(y,0,"int") " w" NumGet(w,0,"int") " h" NumGet(h,0,"int")
	return	{x:NumGet(x,0,"int"), y:NumGet(y,0,"int"), w:NumGet(w,0,"int"), h:NumGet(h,0,"int")}
}
There are alternative versions of Acc.ahk in rbrtryn_3-04-2014.7z:
Index of /joe_df/autohotkey_scripts_archive
https://www.autohotkey.com/joe_df/autohotkey_scripts_archive/

Code: Select all

;~Sean\Lib\Acc.ahk
Acc_Location(Acc, ChildId=0) { ; adapted from Sean's code
	try Acc.accLocation(ComObj(0x4003,&x:=0), ComObj(0x4003,&y:=0), ComObj(0x4003,&w:=0), ComObj(0x4003,&h:=0), ChildId)
	catch
		return
	return	{x:NumGet(x,0,"int"), y:NumGet(y,0,"int"), w:NumGet(w,0,"int"), h:NumGet(h,0,"int")
		,	pos:"x" NumGet(x,0,"int")" y" NumGet(y,0,"int") " w" NumGet(w,0,"int") " h" NumGet(h,0,"int")}
}

;~jethrow\Acc.ahk
Acc_Location(Acc, ChildId=0) { ; adapted from Sean's code
	try Acc.accLocation(ComObj(0x4003, & x := 0)
	                  , ComObj(0x4003,&y:=0)
					  , ComObj(0x4003,&w:=0)
					  , ComObj(0x4003,&h:=0)
					  , ChildId)
	catch
		return
	return { x:NumGet(x,0,"int")
	       , y:NumGet(y,0,"int")
		   , w:NumGet(w,0,"int")
		   , h:NumGet(h,0,"int")
		   , pos:"x" NumGet(x,0,"int")
		      . " y" NumGet(y,0,"int")
			  . " w" NumGet(w,0,"int")
			  . " h" NumGet(h,0,"int") }
}
Last edited by jeeswg on 10 Nov 2019, 06:00, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA



elbeau
Posts: 18
Joined: 08 Aug 2020, 18:20

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

Post by elbeau » 10 Nov 2020, 11:12

I'm trying to figure out how to pull data from a webpage that's using ACC. I have a feeling I'm missing something simple.
I want to pull the wind gusts from a personal weather station like https://www.wunderground.com/dashboard/pws/KNEOMAHA130
I've been able to get the text from the "name" of wind gusts using the script below. However, I can't figure out how to get the name/path of that to poll it without hovering my mouse over it.

Code: Select all

^t:: Msgbox % GetTextUnderMouse() 

GetTextUnderMouse(){
      Acc := Acc_ObjectFromPoint(child)
      try value := Acc.accValue(child)
      if Not value
                  try value := Acc.accName(child)
                 return value
}
return
Separately, AccViewer returns Child ID : 46 Path 1.2
I've searched and tried all sorts of things but cannot pull that value - I always get a blank message box.
mikeyww put together a slick RegEx solution, but I'd really like to solve this puzzle with Acc.

dbareis
Posts: 39
Joined: 04 Feb 2022, 17:57

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

Post by dbareis » 23 Mar 2022, 19:22

I've used "Acc.ahk" to obtain the current URL from the active browser tab, now I'm trying to get the information required to get the path/directory/folder of the current "explorer.exe" tab.

I found "AccViewer.ahk" and it displays its dialog when run, as I move the mouse it doesn't do anything and if I lick the image on the top left it says "Acc_Children Failed" on line 508 (continue script?). I have tried again after restarting my Windows 10 computer. Are there instructions on how to use it somewhere or is it failing for some reason?

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

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

Post by BoBo » 11 May 2022, 16:27

dbareis wrote:
23 Mar 2022, 19:22
I've used "Acc.ahk" to obtain the current URL from the active browser tab, now I'm trying to get the information required to get the path/directory/folder of the current "explorer.exe" tab.

I found "AccViewer.ahk" and it displays its dialog when run, as I move the mouse it doesn't do anything and if I lick the image on the top left it says "Acc_Children Failed" on line 508 (continue script?). I have tried again after restarting my Windows 10 computer. Are there instructions on how to use it somewhere or is it failing for some reason?
Drag & drop AccViewers crosshair over the element for which you wanna see its details.

dbareis
Posts: 39
Joined: 04 Feb 2022, 17:57

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

Post by dbareis » 11 May 2022, 19:06

BoBo wrote:
11 May 2022, 16:27
dbareis wrote:
23 Mar 2022, 19:22
I've used "Acc.ahk" to obtain the current URL from the active browser tab, now I'm trying to get the information required to get the path/directory/folder of the current "explorer.exe" tab.

I found "AccViewer.ahk" and it displays its dialog when run, as I move the mouse it doesn't do anything and if I lick the image on the top left it says "Acc_Children Failed" on line 508 (continue script?). I have tried again after restarting my Windows 10 computer. Are there instructions on how to use it somewhere or is it failing for some reason?
Drag & drop AccViewers crosshair over the element for which you wanna see its details.
Thanks, I worked that out eventually, it shouldn't be that cryptic though.

dbareis
Posts: 39
Joined: 04 Feb 2022, 17:57

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

Post by dbareis » 14 Aug 2022, 22:25

I can't workout how to extract information from this sample page : https://www.findagrave.com/memorial/242628547/dudley-alwin-adcock

The path to BIRTH (21 Apr 1921) is "4,1,1,2,2,2,1,3,2,2,2,2,1,1" according to "AccViewer.ahk" which shows the value I want under "Name" with "Value" blank, those code don't show the birthdate (blank instead)::

Code: Select all

BL                        := "4,1,1,2,2,2,1,3,2,2,2,2,1,1"

xBirthDate := Acc_Get("Object", BL,, "ahk_exe chrome.exe").accValue(0)
MsgBox 0, % "BIRTHDATE 1 : " . BL, % xBirthDate

xBirthDate := Acc_Get("Object", BL,, "ahk_exe chrome.exe").accName(0)
MsgBox 0, % "BIRTHDATE 2 : " . BL, % xBirthDate

dbareis
Posts: 39
Joined: 04 Feb 2022, 17:57

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

Post by dbareis » 15 Aug 2022, 00:03

To answer my own Question above: WTF!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "AccViewer.ahk" generates and displays paths with commas that the "acc" library doesn't support, so convert all commas to full stops.

neogna2
Posts: 586
Joined: 15 Sep 2016, 15:44

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

Post by neogna2 » 15 Aug 2022, 01:58

dbareis wrote:
15 Aug 2022, 00:03
"AccViewer.ahk" generates and displays paths with commas that the "acc" library doesn't support, so convert all commas to full stops.
Yes, a quick fix for that is to replace the line
ToolTip % "clipboard = " clipboard:=SB_Text
with
ToolTip % "clipboard = " clipboard:=StrReplace(SB_Text, ",", ".")

dbareis
Posts: 39
Joined: 04 Feb 2022, 17:57

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

Post by dbareis » 16 Aug 2022, 22:43

neogna2 wrote:
15 Aug 2022, 01:58
dbareis wrote:
15 Aug 2022, 00:03
"AccViewer.ahk" generates and displays paths with commas that the "acc" library doesn't support, so convert all commas to full stops.
Yes, a quick fix for that is to replace the line
ToolTip % "clipboard = " clipboard:=SB_Text
with
ToolTip % "clipboard = " clipboard:=StrReplace(SB_Text, ",", ".")
Thanks for that :-)

It's a pity that there may be many of these "improvements" around but no improvement to the script that everyone downloads... Anyway, I now have my own version with other improvements while I was at it.

dbareis
Posts: 39
Joined: 04 Feb 2022, 17:57

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

Post by dbareis » 12 Oct 2022, 01:36

My scripts are failing on a different computer but I don't know if they would have continued to work on the original or if the latest chrome versions 105 & 106 have broken acc.ahk and the viewer.

The "document" no longer gets expanded (no children):

Code: Select all

...
4.1.1.2.2.2							document [][]
4.1.1.2.3						pane [][]
4.1.1.2.4						pane [][]
4.1.1.2.4.1							pane [][]
4.1.1.2.4.2							separator [][]
4.1.1.2.4.2.1								slider [Side panel resize handle][]
...

neogna2
Posts: 586
Joined: 15 Sep 2016, 15:44

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

Post by neogna2 » 12 Oct 2022, 04:14

dbareis wrote:
12 Oct 2022, 01:36
My scripts are failing on a different computer but I don't know if they would have continued to work on the original or if the latest chrome versions 105 & 106 have broken acc.ahk and the viewer.
I can use v1 acc.ahk and the Acc viewer in the latest version of Chrome without any issues.

dbareis
Posts: 39
Joined: 04 Feb 2022, 17:57

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

Post by dbareis » 12 Oct 2022, 21:35

Thanks for testing, must be this laptop then, it's still on Windows 10, as it partly works there shouldn't be anything I need to turn on...

Post Reply

Return to “Tutorials (v1)”