Search code examples
objective-cmacoscocoaquartz-core

When tapping Quartz events, what is CGEventType 0x1D (29)?


When dealing with Quartz events I can not seem to find any documentation on what event 0x1D, 29 is and how to deal with it.

I have looked here and at an assortment of header files... https://developer.apple.com/documentation/coregraphics/cgeventtype?language=objc

The event in question is produced when using the touch bar and the track pad.

My specific problem is tapping the trapping touch bar soft keys like escape. When the user touches escape, a 0x1D event is fired. If this event isn't returned from the event callback then the kCGEventKeyDown and kCGEventKeyUp events are never fired. If this event is returned then subsequent events are fired like the button is on a traditional keyboard.

eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, 0, kCGEventMaskForAllEvents, myCGEventCallback, NULL);

//No touch bar soft key events will ever fire
CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type,  CGEventRef event, void *refcon) {
     if(type == 0x1D) {
          return NULL;
     }
}

Clearly, I could just always blindly return events of this type, but I would much rather understand what this event represents and what information is available inside it's CGEventRef.


Solution

  • Sometimes things like this are "hidden" in header files. If you take a look at NSEvent.h (CGEventType and NSEventType map onto the same values), you'll find your value:

    // snip...
    /* The following event types are available on some hardware on 10.5.2 and later */
    NSEventTypeGesture NS_ENUM_AVAILABLE_MAC(10_5)       = 29,
    NSEventTypeMagnify NS_ENUM_AVAILABLE_MAC(10_5)       = 30,
    NSEventTypeSwipe   NS_ENUM_AVAILABLE_MAC(10_5)       = 31,
    // snip...
    

    So 29 is a "gesture" event.