Event Tap strangeness
Event Tap strangeness
- Subject: Event Tap strangeness
- From: Martin Redington <email@hidden>
- Date: Tue, 12 Feb 2008 13:13:32 +0000
I'm trying to observe all mouse down and key down events with an
event tap.
Everything seems to work ok, but when I shut the event tap down, I'm
seeing some bizarre event related behaviour in my app and other apps.
These include:
events disappearing (typically a click or key has no effect, until
repeated).
events being passed to the wrong app (e.g. command-D in a file dialog
in my app instead creates a bookmark in Xcode sitting behind it).
events delivery being delayed, or delivered twice. e.g. I hit F11 in
my app, but when I quit the app seconds later, another F11 gets
delivered (i.e. Desktop is revealed).
I'm pretty sure that these are connected to the event tapping,
although not how - they suddenly appeared after I rolled in the event
tapping code. I don't get this for every event - it sometimes seems
as though I get a single misdelivered event just after switching to a
new application, although it's not quite that regular.
I'm using kCGEventTapOptionListenOnly and returning the event
unchanged. I'm pretty sure that its getting shut down correctly, as I
don't see the callback function getting invoked after I stop tapping.
Any suggestions would be great.
cheers,
m.
CGEventRef MyEventTapCallback (
CGEventTapProxy proxy,
CGEventType type,
CGEventRef event,
void *refcon
)
{
[[(CLSilverbackEventTapper *)refcon delegate] handleEvent:event];
return event;
}
- (void) startTapping
{
NSLog(@"Installing event tap");
if(mEventTap != NULL)
{
NSLog(@"WARNING: Event tap already exists");
return;
}
CGEventMask eventsOfInterest = CGEventMaskBit
(kCGEventLeftMouseDown) |
CGEventMaskBit(kCGEventRightMouseDown) |
CGEventMaskBit(kCGEventOtherMouseDown) |
CGEventMaskBit(kCGEventKeyDown);
mEventTap = CGEventTapCreate (
kCGSessionEventTap,
kCGTailAppendEventTap,
kCGEventTapOptionListenOnly,
eventsOfInterest,
MyEventTapCallback,
self
);
if(mEventTap == NULL)
{
NSLog(@"WARNING: Could not create event tap");
return;
}
mEventSrc = CFMachPortCreateRunLoopSource(NULL, mEventTap, 0);
if(mEventSrc == NULL)
{
NSLog(@"No event run loop src?\n");
return;
}
// Get the CFRunLoop primitive for the Carbon Main Event Loop,
and add the new event souce
// CFRunLoopAddSource((CFRunLoopRef) (GetCFRunLoopFromEventLoop
(GetMainEventLoop())), mEventSrc, kCFRunLoopDefaultMode);
CFRunLoopAddSource(CFRunLoopGetCurrent(), mEventSrc,
kCFRunLoopCommonModes);
}
- (void) stopTapping
{
NSLog(@"Removing event tap");
if(mEventSrc)
{
// CFRunLoopRemoveSource((CFRunLoopRef)
(GetCFRunLoopFromEventLoop(GetMainEventLoop())), mEventSrc,
kCFRunLoopDefaultMode);
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), mEventSrc,
kCFRunLoopCommonModes);
CFRelease(mEventSrc);
}
if(mEventTap != NULL)
{
CFRelease(mEventTap);
}
}
_______________________________________________
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