Trouble with CGEvents + AX calls
Trouble with CGEvents + AX calls
- Subject: Trouble with CGEvents + AX calls
- From: Tom Harrington <email@hidden>
- Date: Fri, 19 Feb 2010 15:03:42 -0700
I have some code which monitors mouse events in the background via
GetEventMonitorTarget() and then makes accessibility calls based on
what happens. I'd like to migrate to Quartz events and a CG event tap.
I've been able to get the code working with CGEvents but I'm having
severe performance problems that I'm not sure how to handle.
When modifying the code I replaced the event monitoring with CGEvents
but otherwise left the code alone, making the same accessibility calls
as I've been doing all along. The only change was converting from
using Point to CGPoint. However while the code can easily keep up
with Carbon events, it quickly falls behind processing CGEvents when
the mouse is moving. Events do eventually get processed but they may
be delayed by several seconds. When this happens, my accessibility
code doesn't use any more CPU than it did with Carbon events, but the
WindowServer process can hit over 50% of CPU.
I'm perplexed as to why I'm getting such a difference between the two
event systems. I would have expected my code to perform at least as
well with CGEvents as it does with Carbon events. I'm wondering if I'm
doing something seriously wrong with CGEvents.
I think my code for starting the event tap is pretty generic:
CGEventMask eventMask;
eventMask = CGEventMaskBit(kCGEventFlagsChanged) // Any
modifier keys change state
| CGEventMaskBit(kCGEventMouseMoved)
// Mouse moved
| CGEventMaskBit(kCGEventLeftMouseDown)
// Mouse button
| CGEventMaskBit(kCGEventLeftMouseUp)
// Mouse button
| CGEventMaskBit(kCGEventRightMouseDown)
// Mouse button
| CGEventMaskBit(kCGEventRightMouseUp)
// Mouse button
| CGEventMaskBit(kCGEventOtherMouseDown)
// Mouse button
| CGEventMaskBit(kCGEventOtherMouseUp)
// Mouse button
| CGEventMaskBit(kCGEventScrollWheel)
// Scroll wheel
;
eventPort = CGEventTapCreate(kCGSessionEventTap,
kCGHeadInsertEventTap,
kCGEventTapOptionListenOnly,
eventMask,
cgEventHandler,
NULL );
CFRunLoopSourceRef eventSrc = CFMachPortCreateRunLoopSource(NULL,
eventPort, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), eventSrc, kCFRunLoopDefaultMode);
In my callback I've replaced Carbon event calls with CGEvent calls but
otherwise left things alone. On a mouse move I make the following
calls to get info about the event:
CGPoint mouseLocation = CGEventGetLocation(event);
...
int64_t deltaX = CGEventGetDoubleValueField(event, kCGMouseEventDeltaX);
int64_t deltaY = CGEventGetDoubleValueField(event, kCGMouseEventDeltaY);
Is there something else I need to be doing to get this working fast
enough to be useful?
--
Tom Harrington
email@hidden
AIM: atomicbird1
_______________________________________________
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