• 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: Event Tap(CFMachPortRef) problem for Hot Key- callback is not invoked
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Event Tap(CFMachPortRef) problem for Hot Key- callback is not invoked


  • Subject: Re: Event Tap(CFMachPortRef) problem for Hot Key- callback is not invoked
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Tue, 08 Mar 2011 10:01:16 +0100

Le 8 mars 2011 à 04:40, Deepa a écrit :

> Hi,
>
> I am developing a desktop application that supports one of the feature through Hot Key. I am using Event Tap for this to work.
>
> But, sometimes (randomly) the callback is not invoked; Hot Key does not work and hence the feature seems to be not working.
>
> Could someone help me out in identifying the problem here.
>
> Following is the code snippet:
>
>   -( void )startEventTapinThread //Called in a separate thread.
>   {
>   	NSAutoreleasePool *pool =[ [ NSAutoreleasePool alloc] init];
>
>   	CFRunLoopRef runloop =(CFRunLoopRef)CFRunLoopGetCurrent();
>   	CGEventMask interestedEvents = CGEventMaskBit(kCGEventFlagsChanged)|CGEventMaskBit(kCGEventKeyDown);
>   	CFMachPortRef eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, 0, interestedEvents, myCGEventCallback, self);	//self is the object pointer our method
>   	CFRunLoopSourceRef source = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
>   	CFRunLoopAddSource((CFRunLoopRef)runloop , source, kCFRunLoopCommonModes);
>   	CFRunLoopRun();
>   	[ pool release];
>   }
>
>   CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon)
>   {
>   	CGEventType eventType = CGEventGetType(event);
>   	//execute the code related to feature
>   }



Why you don't use the HotKey API instead (RegisterEventHotKey()) ? It does not require root access or accessibility enabled and it works quite well.


-- Jean-Daniel




_______________________________________________

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: Event Tap(CFMachPortRef) problem for Hot Key- callback is not invoked
      • From: Deepa <email@hidden>
References: 
 >Event Tap(CFMachPortRef) problem for Hot Key- callback is not invoked (From: Deepa <email@hidden>)

  • Prev by Date: Re: Length of NSWindow's stringWithSavedFrame result?
  • Next by Date: Re: Event Tap(CFMachPortRef) problem for Hot Key- callback is not invoked
  • Previous by thread: Event Tap(CFMachPortRef) problem for Hot Key- callback is not invoked
  • Next by thread: Re: Event Tap(CFMachPortRef) problem for Hot Key- callback is not invoked
  • Index(es):
    • Date
    • Thread