这是我的代码:
#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;
}
首先..如果我想编辑事件怎么办?例如,我监听 keyDown 事件,如果它是“a”,我将其转为“b”,或者实时编辑鼠标位置,或者例如简单地捕获一个事件并使其无效(禁用特定的例如键..)
第二.. CGEventType 是用一个仅列出几种类型的枚举定义的.. 例如,当我点击 CMD 时,我得到一个 12,但这与枚举中指定的值不匹配.. 我错过了什么?