For mouse events, you can use CGEventGetIntegerValueField
to get the event's kCGMouseEventSubtype
property.
System-defined events are trickier. CGEvents don't seem to really expose that.
The easy part is matching the events. As long as CGEvent uses the same event type numbers that NSEvent and IOLLEvent use, and as long as event masks are simply combinations of 1 << eventType
, you should be able to use some variation on CGEventMaskBit(NSSystemDefined)
for the registration and CGEventGetType(event) == NSSystemDefined
for testing.
The hard part is telling what a system-defined event's subtype is without going through NSEvent.
One possibility would be to do the same as for a mouse event (use kCGMouseEventSubtype
), but since the layout of NXEventData
is different for mouse events and “compound” (which includes system-defined) events, I wouldn't count on that working.
Most probably, there is no way to get a system-defined event's subtype from a CGEvent, so you would have to create an NSEvent.
Have you considered using NSEvent's event monitor API? If you can require 10.6 or later, you can catch events that way, and you'll get them as NSEvents already, ready for asking their subtypes.