Using the ACC library

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
x32
Posts: 177
Joined: 25 Nov 2016, 16:44

Using the ACC library

15 Jul 2018, 02:12

I'm trying to learn the ACC function library as the tool Accessible Info Viewer finds a lot of information that WindowSpy doesn't. I'm just starting at the top of the Library's Function List to see what information I get from each but it's above my head.

This script receives nothing from the library call and I'm not sure what I'm doing wrong.

Code: Select all

Acc_Init() ; Not sure this is needed.

Gui, Add, Edit, x5 y5 w490 h25 vedit1, 
Gui, Add, Edit, x5 y+5 w490 h25 vedit2, 

Gui, Show,  w500 h70 ,  
Return

!z::
MouseGetPos, OutX, OutY, OutWin, OutCon, 
id = 0xFFFFFFFC    ;    OBJID_CLIENT = 0xFFFFFFFC
GetInfo := Acc_ObjectFromWindow(OutWin,id)
GuiControl, , edit1, %GetInfo%
GuiControl, , edit2, %OutWin%
Return
This is the actual library function.

Code: Select all

Acc_ObjectFromWindow(hWnd, idObject = 0)
	{
		Acc_Init()
		If	DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject&=0xFFFFFFFF, "Ptr", -VarSetCapacity(IID,16)+NumPut(idObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81,NumPut(idObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0,IID,"Int64"),"Int64"), "Ptr*", pacc)=0
		Return	ComObjEnwrap(9,pacc,1)
	}
And this is the instructions from the forum page.

Code: Select all

Acc_ObjectFromWindow(hWnd [, idObject=-4])
- Retrieves the specified interface for the object associated with the specified window.

    Parameters
    hWnd [in]
        Specifies the handle of a window for which an object is to be retrieved.
    idObject [in]
        Specifies the object ID. This value is one of the standard object identifier constants (defaults to OBJID_CLIENT) or a custom object ID such as OBJID_NATIVEOM.
    Return value
    If successful, returns an AHK wrapped IAccessible object.
Can anyone tell me what I'm doing wrong? Thanks
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Using the ACC library

15 Jul 2018, 03:09

- Try this:

Code: Select all

Gui, Add, Edit, x5 y5 w490 h25 vedit1
Gui, Add, Edit, x5 y+5 w490 h25 vedit2
Gui, Add, Edit, x5 y+5 w490 h25 vedit3
Gui, Show, w500 h100
return

!z::
MouseGetPos, OutX, OutY, OutWin, OutCon
id := 0xFFFFFFFC    ;    OBJID_CLIENT = 0xFFFFFFFC
;oAcc := Acc_ObjectFromWindow(OutWin, id), vChildID := 0
oAcc := Acc_ObjectFromPoint(vChildID)
GuiControl,, edit1, % oAcc.accName(vChildID)
GuiControl,, edit2, % oAcc.accValue(vChildID)
GuiControl,, edit3, % OutWin
return
- See also this script that tries to recreate AccViewer but in a simple way:
AccViewer Basic - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=32039
- I haven't ever used Acc_Init. AFAIK it isn't needed, the question is whether it improves performance. Anyone?
- The problem with your script is this line:
GuiControl, , edit1, %GetInfo%
GetInfo is a reference to an object, referring to it like that will just give you a blank string. You probably want to use something like accName or accValue (as in my example).
- Also, if you use Acc_ObjectFromWindow, you would be referring to the window each time, i.e. getting information like the window title only. You might prefer to use Acc_ObjectFromPoint to refer to the GUI element under the cursor (as in my example).
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
x32
Posts: 177
Joined: 25 Nov 2016, 16:44

Re: Using the ACC library

15 Jul 2018, 08:11

That works great, thanks. Although I can't claim to understand it, it is showing me the exact information I was trying to get.

Next question. I can only figure out how to get the control under the mouse. I'm guessing that's what "Acc_ObjectFromPoint" does. Since I know the coordinates of the control, is there a way to retrieve the info without having to have the mouse over it?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Using the ACC library

15 Jul 2018, 09:20

- In Acc.ahk the function is defined like this:

Code: Select all

Acc_ObjectFromPoint(ByRef _idChild_ := "", x := "", y := "")
- So you can specify the coordinates that way, the 2nd and 3rd parameters. Screen coordinates AFAIK (not window/client coordinates).
- To understand the child ID parameter: AccViewer states 'Object' or 'Child Id' in the bottom-left corner. An object is a GUI element/control/window, a child ID is a subelement of a GUI element/control/window. In various Acc functions you can specify a child ID for a particular subelement, otherwise 0 to refer to the object itself.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
x32
Posts: 177
Joined: 25 Nov 2016, 16:44

Re: Using the ACC library

15 Jul 2018, 10:56

Yes, that is working too. It does seem to only work with screen coordinates so I'll have to maximize the window every time . Thanks again.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rohwedder and 356 guests