Assistance with Windows Text via Acc Library Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
theartofx
Posts: 15
Joined: 07 May 2017, 15:50

Assistance with Windows Text via Acc Library

06 Nov 2017, 14:51

Ok, so I have an application that I use at work that has many controls that can't be seen/read by Windows Spy/AHK by default. I've found Acc Library for AHK can read these controls, but only upon mouse-over. Using the AccViewer, I can see the control's child path... and using a couple of the examples and modifying a bit to try to suit my needs, I can read the Firefox's address bar without hovering over it using the Acc_Get() function using the control's child path. In the application I'm attempting to read, this does not work, to read the text, it must be done by the Acc_ObjectFromPoint() function.

Example code I'm trying to get to work:

Code: Select all

#include C:\AutoHotkey\Acc\acc.ahk
SetTitleMatchMode 2
!Q::
MsgBox % "!!" Acc_Get("Value", "3.5.2", 0, "Interaction") ", " Acc_Get("Value", "4.28.3.2", 0, "Firefox")
This outputs the following MsgBox text: !!, https://autohotkey.com/boards/posting.php?mode=post&f=5

I expect to see: !!Research, https://autohotkey.com/boards/posting.php?mode=post&f=5

If I mouse over the control using the following code, it reads it fine:

Code: Select all

#include acc.ahk
!q:: ;get information from object under cursor, 'AccViewer Basic' (cf. AccViewer.ahk)

ComObjError(False)
oAcc := Acc_ObjectFromPoint(vChildId)
vAccName := oAcc.accName(vChildId)
MsgBox % vAccName
This example returns "Research" as expected.

My question is why Acc Library is able to be read upon mouse-over, but not with the Acc_Get pointing to the control's child path that I found with Acc Viewer. The Acc Library is a bit over my head, and I'm having trouble interpreting the gist of it's code. I've tried searching and couldn't find much about this specifically... so if anyone can help with this or give any advice whatsoever, I'd be greatly appreciative. I'm also open to any suggestion on other functions that may be usable in this type of situation. Thanks!
User avatar
jeeswg
Posts: 5956
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Assistance with Windows Text via Acc Library  Topic is solved

06 Nov 2017, 15:55

I tend to do something like this:

Code: Select all

q::
oAcc := Acc_Get("Object", "1.2.3.4", 0, "ahk_id " hWnd)
MsgBox, % oAcc.accName(0) "`r`n" oAcc.accValue(0)
return
- Replace '(0)' with the child ID number if appropriate.
- I often use either the hWnd for the window, or an hWnd (hCtl) for the control as the basis, see the ClassNN field.
- Try just messaging the name or value for item "1" or "1.1". You can use other clues like role or child count, to see what element the Acc object is referring to.
- Try focusing the entire window or the entire control, i.e. the borders are placed around it, and then going down the hierarchy, the hierarchy is relative to the element you focus, it is better if this is a window/control.
- If you've focused a subelement rather than a window or control, try adding more numbers to the start of parameter 2.
- Try practising on a simple window first like Notepad.
- If you can get an object under the cursor, you can almost always (always?) get it via hierarchies.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
theartofx
Posts: 15
Joined: 07 May 2017, 15:50

Re: Assistance with Windows Text via Acc Library

06 Nov 2017, 18:04

jeeswg wrote: - Try focusing the entire window or the entire control, i.e. the borders are placed around it, and then going down the hierarchy, the hierarchy is relative to the element you focus, it is better if this is a window/control.
- If you've focused a subelement rather than a window or control, try adding more numbers to the start of parameter 2.
This was the issue. I was selecting the element, and the "Window" element was "4". So the child path I should have been using was 4.3.5.2. I didn't notice because as you advised, it was only showing the relative path. Thank you kindly jeeswg!

Edit: Also an issue was the use of "Value" instead of "Object" as the cmd for the function. I tried matching it back up as a test, and it returns blank. All in all, very helpful response. Thanks again!
User avatar
jeeswg
Posts: 5956
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Assistance with Windows Text via Acc Library

06 Nov 2017, 19:04

- I'm glad that you were able to solve it, problems with Acc are quite difficult to solve 'by phone', when you aren't both looking at the same screen. Sometimes I anticipate a 10-post exchange.
- Plus, it was quite hard to come up with pointers that were simple, useful, clear, and comprehensive, but not banal or obvious, so I'm glad that I was able to be understood.
- Btw I generally only use 'Object' as the first parameter, and not anything else. Although perhaps I should explore the other options more. Cheers.

[EDIT:]
- Also, I've been considering writing a script to start at the element under the cursor, and work out the hierarchy (or rather, the direct dot-separated path) up to the first control it finds, and generate the relevant bit of code. The problem is that I haven't yet investigated how AccViewer works out the hierarchies. AccViewer is quite a complicated script, the way it's written, although the ideas are not necessarily that complicated, and it's not a super-long script.
- I should check to see how many times 4 is the first number, it seems to be relatively common.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: Brazolek123, Kobaltauge, SALZKARTOFFEEEL and 45 guests