• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Detecting text under mouse
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detecting text under mouse


  • Subject: Re: Detecting text under mouse
  • From: "Mr. George Warner" <email@hidden>
  • Date: Sun, 14 Jun 2009 21:33:06 -0700

On Sun, 14 Jun 2009 14:57:21 +1000, Jacob Rhoden <email@hidden> wrote:
> That is exactly what I am looking for, a "Dictionary" application is
> essentially assisting you with being able to read information on the
> screen. Unfortunately I cannot find any documentation at all on how to
> access a programs accessable information! The only information I can
> find are pages and posts saying there is no documentation!
> Does anyone know where I might find information on how to detect the
> accessability information under the mouse cursor?
> (I continue to search the apple documentation in the mean time)


Go to <http://developer.apple.com/search>
Enter "Accessibility".
Click the "Advanced Search" button.

First hit: "Introduction to Accessibility Overview"
URL: <http://developer.apple.com/documentation/Accessibility/Conceptual/AccessibilityMacOSX/OSXAXIntro/OSXAXintro.html >


Sample code is worth 1K emails: <http://developer.apple.com/samplecode/UIElementInspector/index.html >.

Build and run this to see what this app does (basically logs accessibility info for objects under the mouse to a pane).

To understand this code start in <AppShell.m> in the "awakeFromNib" routine; The first thing it does is check to see if Accessibility is enabled (using AXAPIEnabled):

If this is false then the user will have to open the "Universal Access" system preference panel and check the "Enable access for assistive devices" checkbox. (Before you ask, there is no API to turn Accessibility on; it's a user option.)

Next it creates a system wide observer (using the AXUIElementCreateSystemWide API):

     _systemWideElement = AXUIElementCreateSystemWide();

Now if you jump down to the "updateCurrentUIElement" method you should see:

// Ask Accessibility API for UI Element under the mouse
// And update the display if a different UIElement
if (AXUIElementCopyElementAtPosition( _systemWideElement, pointAsCGPoint.x, pointAsCGPoint.y, &newElement ) == kAXErrorSuccess) ...


That's basically it; you have the element under the mouse. The "stringDescriptionOfUIElement" method is what creates the string that's displayed in the floating utility window. More than likely the info you're interested in is the AXValue when AXRole is "AXStaticText" or "AXTextField" or "AXPopUpButton"; or the AXTitle when the AXRole is "AXButton" or "AXWindow", etc.

Run the app and experiment by moving the mouse around and examining the info in the "Accessibility Inspector" pane.

--
Enjoy,
George Warner,
Schizophrenic Optimization Scientist
Apple Developer Technical Support (DTS)

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: NSRuntime.loadLibrary(/usr/lib/java/libObjCJava.dylib) error
  • Next by Date: Re: UTI not identified correctly for some users.
  • Previous by thread: Re: Detecting text under mouse
  • Next by thread: searching a string in big file
  • Index(es):
    • Date
    • Thread