Re: Trouble with event taps...
Re: Trouble with event taps...
- Subject: Re: Trouble with event taps...
- From: Rob Keniger <email@hidden>
- Date: Tue, 11 Aug 2009 10:45:17 +1000
On 11/08/2009, at 2:37 AM, James W. Walker wrote:
I compared your code to the code that I use that gets key down
successfully. One difference is that I don't immediately CFRelease
the event tap and source, I keep them around as long as I use the
tap. Another is that the first 2 parameters I pass to
CGEventTapCreate are kCGAnnotatedSessionEventTap and
kCGTailAppendEventTap.
James is exactly right, you're releasing the Event Tap before you
enable it. You should not release the event tap if you want to use it,
it needs to hang around for as long as you need it.
// Create a run loop source.
runLoopSource =
CFMachPortCreateRunLoopSource(/*kCFAllocatorDefault*/NULL, eventTap, 0);
CFRelease(eventTap); // !!!!!! This release should not be here!!!!!!
// Add to the current run loop.
CFRunLoopAddSource([[NSRunLoop currentRunLoop] getCFRunLoop],
runLoopSource, kCFRunLoopCommonModes);
// Enable the event tap.
CGEventTapEnable(eventTap, true); //you're using the event tap
here, but you've already released it so the pointer is invalid
CFRelease(runLoopSource);
--
Rob Keniger
_______________________________________________
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