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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to