1

Hy, i'm looking for how to disable event key, and i found one solution here. My probleme is, i always have "Couldn't create event tap!".. Someone can help me pls ! ty...

here the code i have :

bool dontForwardTap = false;

CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) {

    if (CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode) == 0x0B) {
        CGEventSetIntegerValueField(event, kCGKeyboardEventKeycode, 0x09);
    }

    NSLog(@"Event Tap: %d", (int) CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode));

    if (dontForwardTap)
        return nil;
    else
        return event;
}

- (void) tap_keyboard{
    CFRunLoopSourceRef runLoopSource;

    //CGEventMask mask = kCGEventMaskForAllEvents;
    CGEventMask mask = CGEventMaskBit(kCGEventKeyUp) | CGEventMaskBit(kCGEventKeyDown);

    CFMachPortRef eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, mask, myCGEventCallback, NULL);

    if (!eventTap) {
        NSLog(@"Couldn't create event tap!");
        exit(1);
    }

    runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);

    CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);

    CGEventTapEnable(eventTap, true);

    CFRelease(eventTap);
    CFRelease(runLoopSource);

}
Community
  • 1
  • 1
miDark
  • 83
  • 9
  • Did you read the documentattion of `CGEventTapCreate`? Did you add your app to the allowed apps in System Preferences/Security/Privacy? – Willeke Apr 26 '16 at 13:44
  • yes, i discovered it this morning.. and no i didn't add my app i'll do it and try again – miDark Apr 26 '16 at 15:14

0 Answers0