My solution may not be the best for you,
but it works well for me.
Instead of hooking mouse event, I’m listening
for two notifications: kAXMenuItemSelectedNotification and
kAXSelectedChildrenChanged. In my case, the advantage is that I don’t
need to take care of whether the active menu item is selected by mouse or
keyboard, but the disadvantage is that I do need to take care of tracking the front-most
application, means, when the front-most application switched, the notification
listener has to be uninstalled/reinstalled. By the way, if you are only listening
to your own application’s menu, the carbon event kEventMenuTargetItem
could be an alternative.
Regarding to your case A, my guess is that
you are using CGEventTap as a passive listener, if so, the menu command handler
and your event handler are working in a race condition, the result is speculative.
So, if you are using kCGEventTapOptionListenOnly constant in the function call
to CGEventTapCreate, it is worth to give another try with
kCGEventTapOptionDefault.
Chen
From: accessibility-dev-bounces+chen.wang=email@hidden
[mailto:accessibility-dev-bounces+chen.wang=email@hidden] On Behalf Of Brian Krisler
Sent: Sunday, January 17, 2010
2:36 PM
To:
email@hidden
Subject: How to correctly
determine the selected action, from a mouse select?
Hi,
I am developing an application that relies on the accessibility API. My
application
requires knowledge of the mouse selected action (i.e. Edit, Copy). To
gain
access to this action, I have tried two different approaches, EventTaps
and EventHandlers.
Using both of these methods, I have placed listeners on both mouse up
and mouse down
events. When the event is observed, I grab the accessibility
object at the mouse point.
However, in both approaches, I have observed instances where the
selected action is
not reported correctly, depending on the 'habit' of the
individual.
A) If the subject Clicks on 'Edit' and releases on 'Select All', the reported
events would be:
Mouse Up: What ever object is under 'Select All'.
B) If the Subject Clicks and releases on 'Edit', then clicks and
releases on 'Select All', there are 4 events:
For Case B, I can get the proper action 'Select All'. However it
is case A that I miss the action. Is there
a more appropriate method for determining the executed action that the
approaches outlined above? Since
I have no control over the selection habits of my user base, I am
obligated to design my software to
An even more random case is one where the select results in the
dismissal of a window (Send mail for example).
In this case the Mouse Down would be the send button and Mouse Up would
be the action under the composed
Thanks for any suggestions/ideas.