• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Trouble with event taps...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Trouble with event taps...
      • From: Dave Keck <email@hidden>
References: 
 >Trouble with event taps... (From: Nat Burke <email@hidden>)
 >Re: Trouble with event taps... (From: "James W. Walker" <email@hidden>)

  • Prev by Date: CoreData object graph gets confused
  • Next by Date: Re: Trouble with event taps...
  • Previous by thread: Re: Trouble with event taps...
  • Next by thread: Re: Trouble with event taps...
  • Index(es):
    • Date
    • Thread