How do I make Acc.ahk do a basic action like clicking? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
TheBeginner
Posts: 42
Joined: 19 Oct 2018, 12:05

How do I make Acc.ahk do a basic action like clicking?

19 Aug 2019, 03:58

I've tried using this script to make Acc.ahk do a simple click But nothing happened.
I have the Acc.ahk placed in the /lib and obtained the path from accviewer, but nothing happens.

What am I doing wrong? and how do I debug it to get me on the right path?

Code: Select all

#SingleInstance force

c::
WinGet, hWnd, ID, A
    oAcc := Acc_Get("Object", "4.10.1.1.4.1", 0, "ahk_id " hWnd)
	oAcc.accDoDefaultAction(0) 
 Return
 

The application is fully accessible I can interact with it with the built in accessibility features of Windows
****** speech recognition --> Show numbers > X number
and the built in accessibility app of Windows (speech recognition) will click it.

How do I do the same thing with autohotkey?
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How do I make Acc.ahk do a basic action like clicking?  Topic is solved

22 Aug 2019, 12:47

- You appear to be doing the right things. Here are some ideas using Notepad's Find dialog as an example:
- I would use accName/accValue/Acc_Location, to check that I've got the right element.
- I would use JEE_AccGetTextAll to list all elements, and to list the correct Acc paths (AccViewer doesn't always give the right path).
- Perhaps you're not clicking on the right element, maybe it should be a different element e.g. an ancestor/sibling/descendant element.
- Possibly you need to use accDoDefaultAction(n), where n is not 0. E.g. a listview item, rather than the listview as a whole.
- As a workaround, if Acc_Location is giving you the right location, you could use MouseClick to click the element, rather than accDoDefaultAction.

Code: Select all

;[JEE_AccGetTextAll function]
;Acc: get text from all window/control elements - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=40615

q:: ;notepad find dialog - get Acc info
WinGet, hWnd, ID, A
Clipboard := JEE_AccGetTextAll(hWnd, "`r`n")
MsgBox, % "done"
return

w:: ;notepad find dialog - toggle 'Match case' checkbox via accDoDefaultAction (and get element info)
WinGet, hWnd, ID, A
oAcc := Acc_Get("Object", "4.4.4", 0, "ahk_id " hWnd)
oAcc.accDoDefaultAction(0)
oRect := Acc_Location(oAcc)
vEltPos := Format("x{} y{} w{} h{}", oRect.x, oRect.y, oRect.w, oRect.h)
MsgBox, % oAcc.accName(0) "`r`n" oAcc.accValue(0) "`r`n" vEltPos
oAcc := oRect := ""
return

e:: ;notepad find dialog - toggle 'Match case' checkbox via accDoDefaultAction
WinGet, hWnd, ID, A
Acc_Get("DoDefaultAction", "4.4.4", 0, "ahk_id " hWnd)
return

r:: ;notepad find dialog - toggle 'Match case' checkbox via MouseClick
WinGet, hWnd, ID, A
oAcc := Acc_Get("Object", "4.4.4", 0, "ahk_id " hWnd)
oRect := Acc_Location(oAcc)
CoordMode, Mouse, Screen
vCurX := oRect.x + oRect.w/2
vCurY := oRect.y + oRect.h/2
MouseClick,, % vCurX, % vCurY
oAcc := oRect := ""
return
Last edited by jeeswg on 23 Aug 2019, 01:19, 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
TheBeginner
Posts: 42
Joined: 19 Oct 2018, 12:05

Re: How do I make Acc.ahk do a basic action like clicking?

23 Aug 2019, 01:04

jeeswg your awesome!! I'll go over the instructions one by one and see if I can make it work
TheBeginner
Posts: 42
Joined: 19 Oct 2018, 12:05

Re: How do I make Acc.ahk do a basic action like clicking?

23 Aug 2019, 03:35

Tried to run the script on the application, but it gets an error. On notepad it works but on the other application it gives

"A COM call to an ASTA was blocked because the call chain originated in or passed through another ASTA. This call pattern is deadlock-prone and disallowed by apartment call control"

Screenshot
https i.imgur.com /fkley3y.png Broken Link for safety

I can get a lot of information with the inspect.exe, can I use any of it to target an element to perform a default action (video link), Maybe the name of the element? or AutomationID ?
https drive.google.com /file/d/1EvUiUxPO4KdHmDcMJ9AO58iYp0PfmkZz/view?usp=sharing Broken Link for safety
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How do I make Acc.ahk do a basic action like clicking?

23 Aug 2019, 09:43

- I believe inspect.exe uses UI Automation, so that would be a completely different approach.

- My function lists elements.
- It appears to be failing on some elements but not all.
- Basically, you want to add things like 'try'/'catch' and 'continue' to the function, for any elements that would cause errors.
- You could also add FileAppend to the function, so that any info it retrieves *before* the error, can be retrieved by opening a text file.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
TheBeginner
Posts: 42
Joined: 19 Oct 2018, 12:05

Re: How do I make Acc.ahk do a basic action like clicking?

23 Aug 2019, 10:48

inspect.exe has the ability to switch between MSAA (which as I understand it is acc) and UI automation.
It also has the ability to "do default action" for testing purposes

in the link in my previous post there is a video of me using it in the MSAA mode

- Some of the things you mentioned I don't know how to do, I did let the script run its course and then pasted it in the file
Most of the elements are like this it's hard to say what they are referring to

Can I use a name instead of a path?
I could find a name easily with accViewer or inspector.

Code: Select all

4.2.4.7.2						push button [][]

4.2.4.7.2.1							graphic [][]

4.2.4.7.2.2							graphic [][]

4.2.4.7.3						push button [][]

4.2.4.7.3.1							graphic [][]

4.2.4.7.3.2							graphic [][]

4.2.4.7.4						push button [][]

4.2.4.7.4.1							graphic [][]
TheBeginner
Posts: 42
Joined: 19 Oct 2018, 12:05

Re: How do I make Acc.ahk do a basic action like clicking?

25 Aug 2019, 08:01

Thanks jeeswg !!! you got me on the right path solution :superhappy:
the function was a big help
chriskeith21
Posts: 5
Joined: 03 Nov 2019, 22:54

Re: jeeswg's homepage

08 Nov 2019, 15:59

Hello @jeeswg , can you give me an example of checking a box with ACC only if it's unchecked or value is false? What I have below will toggle the checkbox but I only want it the action performed if it's unchecked. Anything that is already checked, I want to leave checked. I tried to search it and can't find it.

FrameWorkHwnd:=WinExist("A")
oarefills := Acc_Get("Object", "4.1.4.1.4.1.4.9.1.10", 1, "ahk_id " FrameWorkHwnd)
oarefills.accDoDefaultAction(0)
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's homepage

08 Nov 2019, 16:23

Here is an example to toggle/set/unset 'Match case' in Notepad's Find dialog.
The key thing is to get the element's accState and check for STATE_SYSTEM_CHECKED := 0x10.

Code: Select all

q:: ;notepad find dialog - toggle 'Match case'
WinGet, hWnd, ID, A
oAcc := Acc_Get("Object", "4.4.4", 0, "ahk_id " hWnd)
;MsgBox, % Format("0x{:X}", oAcc.accState(0))
oAcc.accDoDefaultAction(0)
oAcc := ""
return

w:: ;notepad find dialog - 'Match case' set to ticked
WinGet, hWnd, ID, A
oAcc := Acc_Get("Object", "4.4.4", 0, "ahk_id " hWnd)
;MsgBox, % Format("0x{:X}", oAcc.accState(0))
if !(oAcc.accState & 0x10) ;STATE_SYSTEM_CHECKED := 0x10
	oAcc.accDoDefaultAction(0)
oAcc := ""
return

e:: ;notepad find dialog - 'Match case' set to unticked
WinGet, hWnd, ID, A
oAcc := Acc_Get("Object", "4.4.4", 0, "ahk_id " hWnd)
;MsgBox, % Format("0x{:X}", oAcc.accState(0))
if (oAcc.accState & 0x10) ;STATE_SYSTEM_CHECKED := 0x10
	oAcc.accDoDefaultAction(0)
oAcc := ""
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
chriskeith21
Posts: 5
Joined: 03 Nov 2019, 22:54

Re: jeeswg's homepage

08 Nov 2019, 17:13

Awesome! Thanks so much. I also just tried using the accvalue and it seems to work. If value is not true then ... Do you find Value or State to be more reliable?
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's homepage

08 Nov 2019, 17:30

I tested this with Notepad's Find dialog, and according to AccViewer, the value of the checkbox was always blank, whether ticked or unticked, so I had to query the state.

For your example, perhaps the value and state are equally reliable indicators. I would do some tests.

One thing to note, for some elements you can set the accValue, if that works, you don't have to retrieve the state, or use accDoDefaultAction, you could just set the value directly. But ... sometimes with GUIs, you can change the *appearance* of something, but the internally-stored value remains the same.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
chriskeith21
Posts: 5
Joined: 03 Nov 2019, 22:54

Re: jeeswg's homepage

08 Nov 2019, 18:59

Ok, thanks. I will do more testing. I had one more question that I can't figure out. I'm trying to use ACC to select several items in a list box. The main issue with this listbox is that it's not static. But I have figured out how to highlight an item but I can't get it to highlight more than one item. The below code highlights the first item then unselects and highlights the next item.
Any advice? Before my software changed to the 4.0 windows, I was able to choosestring and I could select the fields that I wanted but I'm not sure how to do with ACC. The goal would be to highlight all fields at once with "abc" as the value.
FrameWorkHwnd:=WinExist("A")
oListSelection1 := Acc_Get("Object", "4.1.4.1.4.1.4.6.2.4", 0, "ahk_id " FrameWorkHwnd)
oListSelection2 := Acc_Get("Object", "4.1.4.1.4.1.4.6.2.5", 0, "ahk_id " FrameWorkHwnd)
oListSelection1.accSelect(ComObj(3,3),0)
oListSelection2.accSelect(ComObj(3,3),0)

Also, I apologize if I commented in the wrong post. I just new you were very knowledgeable on ACC and I wanted to ask you. Thanks for your time.
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's homepage

08 Nov 2019, 19:05

Consider the various constants here:
SELFLAG Constants - Win32 apps | Microsoft Docs
https://docs.microsoft.com/en-us/windows/win32/winauto/selflag

Then do the following (change 0x3/vIndex as appropriate):

Code: Select all

;SELFLAG_ADDSELECTION := 0x8
;SELFLAG_TAKESELECTION := 0x2 ;SELFLAG_TAKEFOCUS := 0x1
oAcc.accSelect(0x3, vIndex)
Last edited by jeeswg on 08 Nov 2019, 19:08, 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
chriskeith21
Posts: 5
Joined: 03 Nov 2019, 22:54

Re: jeeswg's homepage

08 Nov 2019, 19:08

Great! Thanks. I’ll try this out when I get home.
chriskeith21
Posts: 5
Joined: 03 Nov 2019, 22:54

Re: How do I make Acc.ahk do a basic action like clicking?

08 Nov 2019, 23:52

Thanks for that info. I got that to work now the issue is that every time I move the scroll bar, the path resets. I'm trying to highlight some fields halfway down the scroll bar but they have the same path as many other items in the listbox.
I attached a picture. I'm not sure if there are any other options because every time I scroll down, the paths don't change even thought the fields are different.
So the top cell is 6.2.1.1 and goes all the way down to 6.2.24.1 Then when I scroll down to different text, the paths are the same as before. I was hoping they would just continue but they stop at 6.2.24.1
I hope that makes sense. Do you see any options here? I'm stuck. Thanks
Attachments
fdsafdasfasfaaf.PNG
fdsafdasfasfaaf.PNG (96.03 KiB) Viewed 194 times

Return to “Ask For Help”

Who is online

Users browsing this forum: agrout, Bing [Bot], JoeWinograd, maxkill, Schezza and 83 guests