1
votes

Using the accessibility API, I am drilling down through a series of elements and finding a specific AXUIElementRef I am interested in (all in an external application). How do I check if this element currently has keyboard focus? And if not, how do I set it?

Something similar to using AXUIElementSetAttributeValue to set the kAXMainAttribute to true (this works for a window - thanks Peter!).

PS - I have tried kAXFocusedAttribute, doesn't seem to do the job. Maybe it's read only?

1

1 Answers

1
votes

PS - I have tried kAXFocusedAttribute, doesn't seem to do the job. Maybe it's read only?

Quite the opposite. Read the header:

Writable? Yes, for any focusable element. No in all other cases.

Make sure you've activated the application (by setting its kAXFrontmostAttribute to true) and made the window key (by setting its kAXFocusedAttribute to true) before you give a control in the window focus (by setting its kAXFocusedAttribute to true).