Here's my code:
#import <ApplicationServices/ApplicationServices.h>
CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) {
printf("%u\n", (uint32_t)type);
return event;
}
int main (int argc, const char * argv[]) {
CFMachPortRef eventTap;
CFRunLoopSourceRef runLoopSource;
eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, 0, kCGEventMaskForAllEvents, myCGEventCallback, NULL);
runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
CGEventTapEnable(eventTap, true);
CFRunLoopRun();
return 0;
}
First.. what if I wanted to edit the event? For example I listen for the keyDown event and if it's an "a" I turn it in a "b", or edit the mouse position in real time, or for example simply capture an event and make it have no effect (disabling a particular key for example..)
Second.. CGEventType is defined with an enum that lists only a few types.. for example when I hit CMD I get a 12, but that doesn't match the value specified in the enum.. what I'm I missing??