Trouble with event taps...
Trouble with event taps...
- Subject: Trouble with event taps...
- From: Nat Burke <email@hidden>
- Date: Sun, 9 Aug 2009 15:15:24 -0700
Hi all,
I'm having some difficulty with event taps. I am creating my event tap
from the 'awakeFromNib' function for my overloaded NSWindow.
The problem is that keyUp and keyDown events are never trapped in my
callback. I can see all the mouse events, and even the modifier keys
(shift, option, command, etc) are trapped fine. My callback function just
logs stuff to the console and returns the event. My little debug prints
also show that no bits in the eventMask are cleared away. Also, I do have
'Enable Assistive Devices' checked (or else I wouldn't even get the mouse
events I'd imagine), so I don't think thats the problem.
I have posted my event tap creation code below - I've searched all over
the mailing list and the net to see if I could find a solution, but I am
genuinely stuck. Any help is greatly appreciated!
// Create an event tap.
eventMask = CGEventMaskBit(kCGEventRightMouseDown) |
CGEventMaskBit(kCGEventRightMouseUp) |
CGEventMaskBit(kCGEventRightMouseDragged) |
CGEventMaskBit(kCGEventMouseMoved) |
CGEventMaskBit(kCGEventScrollWheel) |
CGEventMaskBit(kCGEventFlagsChanged) |
CGEventMaskBit(kCGEventKeyDown) |
CGEventMaskBit(kCGEventKeyUp);
DebugLog(@"Event before: %x", eventMask);
eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap,
kCGEventTapOptionDefault, eventMask, MouseCallback, self);
DebugLog(@"Event after: %x", eventMask);
if (!eventTap) {
fprintf(stderr, "Failed to create event tap\n");
exit(1);
}
// Create a run loop source.
runLoopSource =
CFMachPortCreateRunLoopSource(/*kCFAllocatorDefault*/NULL, eventTap, 0);
CFRelease(eventTap);
// Add to the current run loop.
CFRunLoopAddSource([[NSRunLoop currentRunLoop] getCFRunLoop],
runLoopSource, kCFRunLoopCommonModes);
// Enable the event tap.
CGEventTapEnable(eventTap, true);
CFRelease(runLoopSource);
_______________________________________________
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