AccessibleObjectFromWindow does not execute method accFocus in Firefox

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

AccessibleObjectFromWindow does not execute method accFocus in Firefox

24 Dec 2018, 08:39

If We run https://www.google.com in Firefox, then place mouse in front of goole search input and press f11, then we will get focused control from AccessibleObjectFromPoint function, but we will not get focused control from AccessibleObjectFromWindow function.

Code: Select all

f11::
Acc := Acc_ObjectFromPoint()
GoSub test
Acc := Acc_ObjectFromWindow(WinExist("A"))
GoSub test
return

test:
loop
{
   if isobject(Acc.accFocus)
      Acc := Acc.accFocus
   else
   {
      Child := Acc.accFocus
      if (Child = "")
         tooltip no
      else
         tooltip % acc.accName(Child)
      sleep 2000
      return
   }
}
Anybody knows why?
Thank You!
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: AccessibleObjectFromWindow does not execute method accFocus in Firefox

26 Dec 2018, 12:51

- Hmm, so you're testing the GUI element under the cursor in Firefox, on Google's input field. Hovering over it, with it either active or inactive. I got similar results to you, although it was inconsistent, getting 'Search' for the first one sometimes, sometimes nothing, and always nothing for the second one.
- Based on this test script, only sometimes does an Acc object have an accFocus object or value.
- It seems plausible to suppose that you could start at an Acc object for a window, and use accFocus all the way down until you get to the focused GUI element, however, based on my tests, only some elements in the hierarchy returned an Acc object or value.
- I did not know what I should expect when performing accFocus on an object, although I've provided two links below for reference. I only use accFocus myself on controls such as listview controls, to identify the index of the focused item. Cheers.

Code: Select all

;[JEE_AccGetPath and JEE_AccGetEnumIndex functions]
;How to get the full ACC path for control on cursor? - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=5&t=56470&p=254902#p254902

q:: ;test accFocus - only sometimes does an Acc object have an accFocus object/value
WinGet, hWnd, ID, A
oAcc1 := Acc_ObjectFromPoint()
vAccPath1 := JEE_AccGetPath(oAcc1, hWnd)
oAcc2 := Acc_ObjectFromWindow(hWnd)
vAccPath2 := JEE_AccGetPath(oAcc2, hWnd)
MsgBox, % vAccPath1 "`r`n" vAccPath2

vAccPath := ""
Loop, Parse, vAccPath1, % "."
{
	vAccPath .= (A_Index=1?"":".") A_LoopField
	oAcc := Acc_Get("Object", vAccPath, 0, "ahk_id " hWnd)
	MsgBox, % vAccPath "`r`n" "accFocus is object: " IsObject(oAcc.accFocus) "`r`n" "accFocus value: " oAcc.accFocus "`r`n" "accName: " oAcc.accName(0) "`r`n" "accValue: " oAcc.accValue(0)
}
return
- Links:
IAccessible.accFocus Property (Accessibility) | Microsoft Docs
https://docs.microsoft.com/en-us/dotnet ... work-4.7.2
IAccessible::get_accFocus | Microsoft Docs
https://docs.microsoft.com/en-gb/window ... t_accfocus
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: AccessibleObjectFromWindow does not execute method accFocus in Firefox

26 Dec 2018, 15:48

As I understand when You performing accFocus on an object You should expect getting IDispatch Interface:
https://autohotkey.com/board/topic/7730 ... ntry493735
I also tried to test it with ComObjQuery - the same result.

Code: Select all

f11::
Acc := Acc_ObjectFromWindow(WinExist("A"))
loop
{
   AccPtr := ComObjQuery(Acc, "{618736E0-3C3D-11CF-810C-00AA00389B71}")
   ObjRelease(Acc)
   DllCall(NumGet(NumGet(AccPtr+0), 18*A_PtrSize), "ptr", AccPtr, "ptr", VarSetCapacity(Variant, 8+2*A_PtrSize, 0)*0 + &Variant)
   VarType := NumGet(&Variant + 0, 0, "Ushort")
   Acc := NumGet(&Variant + 8, VarType = 9 ? "UPtr" : "Int")
   If (VarType = 9) ; VT_DISPATCH
      Continue
   else If (VarType = 3)   ; VT_I4 (ChildID)
   {
      AccNew := ComObject(9, AccPtr, 1), ObjAddRef(AccPtr)
      msgbox %  AccNew.accValue(Acc)
      return
   }
   else
   {
      ObjRelease(Acc)
      msgbox No Focus
      return
   }
}
If we check Firefox with inspect.exe with settings "watch focus" - it will work in Firefox.
https://raw.githubusercontent.com/black ... nspect.exe
Therefore interesting - is it bug of autohotkey or inspect.exe get info about focused element with different algorithm?
safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: AccessibleObjectFromWindow does not execute method accFocus in Firefox

06 Jan 2019, 06:27

I was looking into Acc related stuff and I found this thread.

I couldn't reproduce this problems. For me AccessibleObjectFromPoint returns the deepest child under mouse (except the first time you open firefox) so, understandably, it can't access the focused elements of the window. And AccessibleObjectFromWindow returns the focused element properly.

I know this doesn't solve your problem, but at least I thought it was good to point it out.
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: AccessibleObjectFromWindow does not execute method accFocus in Firefox

06 Jan 2019, 06:48

Does this code return focused element in firefox?

Code: Select all

f11::
Acc := Acc_ObjectFromWindow(WinExist("A"))
loop
{
   if isobject(Acc.accFocus)
      Acc := Acc.accFocus
   else
   {
      Child := Acc.accFocus
      if (Child = "")
         tooltip no
      else
         tooltip % "yes`n" acc.accName(Child)
      sleep 2000
      return
   }
}
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: AccessibleObjectFromWindow does not execute method accFocus in Firefox

06 Jan 2019, 06:56

For me it returns an element, but only when I press F11 second time.
safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: AccessibleObjectFromWindow does not execute method accFocus in Firefox

06 Jan 2019, 07:00

Yes, but fails the first times sometimes.

Win10, Ahk and FF all in 64bits.
And just in case, the relevant part of my Acc library being (I have some tweaks that shouldn't be important, to be able to use it with #warn mode):

Code: Select all

Acc_Init() {
	Static h:=""
	If Not h
		h := DllCall("LoadLibrary","Str","oleacc","Ptr")
}
Acc_ObjectFromWindow(hWnd, idObject = -4) {
	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)
}
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: AccessibleObjectFromWindow does not execute method accFocus in Firefox

06 Jan 2019, 07:13

safetycar, try Your library.
Win7 64 bit, firefox v64.
Does not work with firefox at all.
teadrinker did You test it in win7?
safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: AccessibleObjectFromWindow does not execute method accFocus in Firefox

06 Jan 2019, 07:32

I did not test it in Win7, I can't help you with that. What's the code for your Acc_ObjectFromWindow then?
safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: AccessibleObjectFromWindow does not execute method accFocus in Firefox

06 Jan 2019, 08:15

@malcev The library is about the same, there must have been some misunderstanding between us. But in the end I think the library you're using seems normal, I don't think that's the matter.
Looks like there's some problem with Win7, I can't help too much with that, maybe someone else.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 132 guests