Issue with CGEventTapCreate() call.

Posted by Dheeraj on Stack Overflow See other posts from Stack Overflow or by Dheeraj
Published on 2010-06-01T04:51:46Z Indexed on 2010/06/01 5:23 UTC
Read the original article Hit count: 564

Filed under:
|

Hi All,

I'm trying to register for global key events using this code :

void function() {

CFMachPortRef keyUpEventTap = CGEventTapCreate(kCGHIDEventTap,kCGHeadInsertEventTap,kCGEventTapOptionListenOnly,CGEventMaskBit(kCGEventKeyUp),&keyUpCallback,NULL);

CFRunLoopSourceRef keyUpRunLoopSourceRef = CFMachPortCreateRunLoopSource(NULL, keyUpEventTap, 0);

CFRelease(keyUpEventTap);

CFRunLoopAddSource(CFRunLoopGetCurrent(), keyUpRunLoopSourceRef, kCFRunLoopDefaultMode);

CFRelease(keyUpRunLoopSourceRef);

}

The application crashes while executing CFMachPortCreateRunLoopSource() call. I think the crash is because of CGEventMaskBit(kCGEventKeyUp) when I create an event tap.

But if I create event tap using CGEventTapCreate(kCGHIDEventTap,kCGHeadInsertEventTap,kCGEventTapOptionListenOnly,CGEventMaskBit(kCGEventFlagsChanged),&keyUpCallback,NULL), the application works fine. It does not crash. I'm getting callbacks when any modifier key is pressed. But I need to get callbacks for delete key pressed.

Any ideas?

Thanks,

Dheeraj.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa