Here is 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 an event? For example, I listen to the keyDown event, and if it is “a”, I turn it into “b” or edit the mouse position in real time or, for example, just capture the event and have no effect (disabling a certain key, for example ..)
Second. CGEventType is defined by an enumeration that lists only a few types. For example, when I press CMD, I get 12, but this does not match the value indicated in the listing .. what am I missing ??
source share