Re: Event Tap(CFMachPortRef) problem for Hot Key- callback is not invoked
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: Deepa <email@hidden>
- Date: Tue, 08 Mar 2011 14:45:55 +0530
- "x-copyrighted-material: http://www.robosoftin.com"
Hi Daniel,
Thank you for the response.
Our app provides the user with an option of using system shortcut keys for capturing.
For example,
Suppose Cmd+Shift+4 is the system shortcut used to capture the full screen; user can use the same combination of keys to capture the full screen from my app.
If I use the Hot key API RegisterEventHotKey(), I cannot override the system behavior with my app behavior for the shortcut Cmd+Shift+4.
So, I am using the tapping mechanism if user wants to override system behavior.
But, sometimes I do not get any callback. How do I solve this?
Regards,
Deepa
On 08-Mar-2011, at 2:31 PM, Jean-Daniel Dupas wrote:
>
> 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
>
>
>
>
>
-----------------------------------------------
Robosoft Technologies - Come home to Technology
Disclaimer: This email may contain confidential material. If you were not an intended recipient, please notify the sender and delete all copies. Emails to and from our network may be logged and monitored. This email and its attachments are scanned for virus by our scanners and are believed to be safe. However, no warranty is given that this email is free of malicious content or virus.
_______________________________________________
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