views:

102

answers:

1

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?

A: 

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).

Peter Hosey
I'm getting an error code - 25205 - back from the set method. No idea where to find out what this could be - I don't even know what language I'm using at this point...Presumably if there is a hierarchy of elements I need to focus on each of them in turn down to the one I want? Or once i'm in the app and window, is that enough?
Ben Packard
The errors are named in AXError.h. And you are using C (possibly within Objective-C).
Peter Hosey