Hello,
I was wondering if it is possible to get an Acc Object from where the focus in a Windows currently is. More precisely where the focus is after using Tab Key.
I usually tab through the elemnts, check if the text matches and send Enter. I would like to achive this with Acc since the Windows 10 Settings windows are not accessible with the standard methods, however very good accessible with help of the Acc Lib.
I built a workaroud with Click to move the Cursor and using Acc_ObjectFromPoint. Its not very "reliable" tho.
How would I go about building something like "Acc_ObjectFromFocus"?
Thanks
Acc Lib, get Acc Object from focus (where Tab key is)
-
- Posts: 343
- Joined: 08 Jun 2019, 17:36
Re: Acc Lib, get Acc Object from focus (where Tab key is)
Hi, I found this while searching a while back and it did seem to work.
I'm not totally sure how the while loop works so maybe someone can shed some light
Code: Select all
Acc_Focus(hWnd)
{
Acc := Acc_ObjectFromWindow(hWnd)
While IsObject(Acc.accFocus)
Acc := Acc.accFocus
return Acc
}
Re: Acc Lib, get Acc Object from focus (where Tab key is)
This does work indeed. Shouldve asked before writting the workaround lol.
According to this site...
https://docs.microsoft.com/en-us/dotnet/api/accessibility.iaccessible.accfocus?view=net-5.0
...the accFocus "call" returns an Object if successful and an error code if not.
So the while loop returns the last object were the accFocus call returns successfully.
Reasonable enough for me. I'll use it.
Thanks a lot.
According to this site...
https://docs.microsoft.com/en-us/dotnet/api/accessibility.iaccessible.accfocus?view=net-5.0
...the accFocus "call" returns an Object if successful and an error code if not.
So the while loop returns the last object were the accFocus call returns successfully.
Reasonable enough for me. I'll use it.
Thanks a lot.
Re: Acc Lib, get Acc Object from focus (where Tab key is)
just doing this works too:
Code: Select all
if (IsObject(acc_window.accFocus))
{
acc_window_focus := acc_window.accFocus
}
else
{
msgbox % "nope"
}
Re: Acc Lib, get Acc Object from focus (where Tab key is)
That returns a different Acc object, at least for some windows, compared to the earlier function by doubledave22 with the While loop. That's at least what I see when I try both on the AutoHotkey.chm help file window.newvice wrote: ↑25 Jul 2021, 15:13just doing this works too:
Code: Select all
if (IsObject(acc_window.accFocus)) { acc_window_focus := acc_window.accFocus } else { msgbox % "nope" }
It appears the function with the While loop first gets an Acc object with focus that is closest to the window's "root". Then it recursively calls accFocus to get a new object "downstream" from the previous one, one or more steps out on a branch in the Acc "tree". Until there is no more downstream child object that satisfies whatever test accFocus uses to determine if an object has keyboard focus.
The function with If only calls accFocus once and because of that returns the Acc object with keyboard focus that is closest to the window's "root".
An older thread about accFocus.
Re: Acc Lib, get Acc Object from focus (where Tab key is)
great explanation, thanksneogna2 wrote: ↑27 Jul 2021, 11:13That returns a different Acc object, at least for some windows, compared to the earlier function by doubledave22 with the While loop. That's at least what I see when I try both on the AutoHotkey.chm help file window.newvice wrote: ↑25 Jul 2021, 15:13just doing this works too:
Code: Select all
if (IsObject(acc_window.accFocus)) { acc_window_focus := acc_window.accFocus } else { msgbox % "nope" }
It appears the function with the While loop first gets an Acc object with focus that is closest to the window's "root". Then it recursively calls accFocus to get a new object "downstream" from the previous one, one or more steps out on a branch in the Acc "tree". Until there is no more downstream child object that satisfies whatever test accFocus uses to determine if an object has keyboard focus.
The function with If only calls accFocus once and because of that returns the Acc object with keyboard focus that is closest to the window's "root".
An older thread about accFocus.
Who is online
Users browsing this forum: Google [Bot], mebelantikjaya, OrangeCat and 296 guests