There is one more API called API AXUIElementCreateSystemWide()
could also be helpful in finding the focused accessibility element regardless
of which application is currently active.
Here is the documentation
http://developer.apple.com/documentation/Accessibility/Reference/AccessibilityLowlevel/AXUIElement_h/CompositePage.html#//apple_ref/c/func/AXUIElementCreateSystemWide
and more ADC discussions:
http://lists.apple.com/archives/carbon-dev/2005/Aug/msg00428.html
http://lists.apple.com/archives/accessibility-dev/2006/Jun/msg00012.html
http://lists.apple.com/archives/carbon-dev/2006/Sep/msg00626.html
Chen
From:
accessibility-dev-bounces+chen.wang=email@hidden
[mailto:accessibility-dev-bounces+chen.wang=email@hidden] On Behalf Of Patti Hoa
Sent: Wednesday, February 11, 2009
2:35 PM
To: Chris Idou
Cc: email@hidden
Subject: Re: Accessibility -
currently selected text
Accessibility Inspector obtains the element under the mouse
via AXUIElementCopyElementAtPosition. Then it asks the element for
all of its available attributes, via AXUIElementCopyAttributeNames.
For each of the attribute, it then displays the returned value for that
attribute.
In your case, it sounds like you are not fetching the UIElement via
mouse position. So let's say you have the application UIElement already.
Here's what you do:
1. Get the keyboard focused UIElement of the application.
The way to get the keyboard focused UIElement of that application is to
ask the application UIElement for its AXFocusedUIElement attribute.
If a text field currently has the keyboard focus, then
that UIElement would be returned as the value
of AXFocusedUIElement.
2. Determine if the AXFocusedUIElement is a text.
See if the AXFocusedUIElement has one of the text AXRole, like
AXTextField/AXTextArea. Use AXUIElementCopyAttributeValue to get
back the AXRole given an UIElement.
3. Determine if the text is editable, if that's your criteria
Use AXUIElementIsAttributeSettable with AXValue as the parameter
to see if this attribute is settable.
4. Ask for the selection via parameterized attribute
Use AXUIElementCopyAttributeValue to get the AXSelectedTextRange.
For example, let's say you are looking at a Cocoa
text field that contains the words "hello world" and the word
"hello" is selected. AXSelectedTextRange should return a range
of 0 to 5. Then call AXUIElementCopyParameterizedAttributeNames
with that CFRange as a parameter to AXAttributedStringForRange to get back
an attribute string containing the word "hello". Alternatively,
you can ask for AXStringForRange if you don't care about the attributes of
the text.
5. Alternative way to ask for selected text.
Use AXUIElementCopyAttributeValue to get the AXSelectedText.
This should also give you back the selected string.
On Feb 10, 2009, at 7:58 PM, Chris Idou wrote:
I've read the doco and looked at
the Accessibility Inspector code, but I'm still struggling with this.
How do I obtain the currently selected
text from the currently focused component of the currently active application?
Make Yahoo!7 your
homepage and win a trip to the Quiksilver Pro. Find out more._______________________________________________
Do not post admin requests to the list. They will be ignored.
Accessibility-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden