• 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: "James W. Walker" <email@hidden>
  • Date: Mon, 10 Aug 2009 09:37:33 -0700


On Aug 9, 2009, at 3:15 PM, Nat Burke wrote:

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);


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.


_______________________________________________

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: Rob Keniger <email@hidden>
    • Re: Trouble with event taps...
      • From: Nat Burke <email@hidden>
References: 
 >Trouble with event taps... (From: Nat Burke <email@hidden>)

  • Prev by Date: Disabled controls don't update their visual appearance
  • Next by Date: Re: NSData Questions
  • Previous by thread: Re: Trouble with event taps...
  • Next by thread: Re: Trouble with event taps...
  • Index(es):
    • Date
    • Thread