Descolada/UIAutomation

How do I find the identifiers for EventHandlers?

Closed this issue · 7 comments

I looked at one of your example files (Example7_FocusChangedEvent.ahk) that had a line with some Chrome address bar identifier, URLEditElement, and couldn't find said identifier via UIAViewer. What am I missing?

I suppose maybe via Windows SDK's inspect.exe? That thing freezes upon launch for me, no matter which of the 6 versions of it that came with Windows SDK I use.

cUIA.URLEditElement is an element queried by the UIA_Browser library, it is not an identifier. In Chrome UIA_Browser searches for the first edit-type element and stores it in the URLEditElement property.

You should use Accessibility Insights as an inspection tool, as inspect.exe is very old and deprecated.

cUIA.URLEditElement is an element queried by the UIA_Browser library, it is not an identifier. In Chrome UIA_Browser searches for the first edit-type element and stores it in the URLEditElement property.

You should use Accessibility Insights as an inspection tool, as inspect.exe is very old and deprecated.
I use Accessibility Insights now but I'm still confused about what to do as the docs are too unclear to me and the examples .ahk files are too complicated.

What am I supposed to do if I want to fire a MsgBox in reaction to LocalizedControlType =data item, Name=26 and BoundingRectangle=[l=1746,t=573,r=1797,b=618]? (Those are the values that occur upon me clicking day 26 of the month.)
2024-07-25_17-15-54

@ars4l4n one possible solution:

#Requires Autohotkey v1
#NoEnv
SetBatchLines, -1
#include <UIA_Interface>

UIA := UIA_Interface()

WinTitleUnderMouse() {
    MouseGetPos,,, hWnd
    WinGetTitle, wTitle, ahk_id %hWnd%
    return wTitle
}

#If WinTitleUnderMouse() = "Date and Time Information"
~LButton::
    el := UIA.ElementFromPoint()
    if (el.Type = UIA.UIA_DataItemControlTypeId && el.Name = "26")
        MsgBox 26 was selected
    return

You could also probably use FocusedChangedEvent, but it would be more difficult.

Pretty good, but how do I include el.BoundingRectangle = "[l: 1534 t: 432 r: 1585 b: 477]")?

This is important because I need to differentiate between the 1st of July and the 1st of August.

It didn't work like:

    if (el.Type = UIA.UIA_DataItemControlTypeId && el.Name = "1" && el.BoundingRectangle = "[l: 1534 t: 432 r: 1585 b: 477]")
        MsgBox August the 1st was selected
br := el.BoundingRectangle
if (el.Type = UIA.UIA_DataItemControlTypeId && el.Name = "1" && br.l = 1534 && br.t = 432 && br.r = 1585 && br.b = 477)
    MsgBox August the 1st was selected

Though I'd just extract the month from the window: MsgBox % "26 was selected in " el.FindByPath("p.p.1").Name

It's behaving weirdly: It identifies clicking August, 1st correctly but it fires both message boxes when clicking on July, 1st.
Code:

    if (el.Type = UIA.UIA_DataItemControlTypeId && br.l = 1534 && br.t = 432 && br.r = 1585 && br.b = 477)
        Msgbox, ,"Day 1 was selected in Juli"
    else (el.Type = UIA.UIA_DataItemControlTypeId && br.l = 1694 && br.t = 619 && br.r = 1745 && br.b = 664)
        MsgBox "Day 1 was selected in August " 

Also, I don't quite get the logic behind el.FindByPath("p.p.1") aside from that it searches in some path. I mean shouldn't el.FindByPath("p.p.p.p.p.1") return data item '1' here?
ApplicationFrameHost_2024-07-29_14-41-16
It just returns an error.

Anyway, I'm noticing el.FindByPath("p.p.1") doesn't differentiate between July and August when those months are on the same page.

I think I'd like to do it via the GridItem method but I don't get how it works.

still haven't figured this out