问题描述
这是我的代码:
#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,或者实时编辑鼠标位置,或者例如简单地捕获一个事件并使其不起作用关键例如..)
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..)
第二.. CGEventType是一个列出只有几个类型的枚举,例如当我打CMD我得到一个12,但是这不符合枚举中指定的值..我缺少什么?
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??
推荐答案
修改事件,有各种CGEventSet ...功能。为了杀死事件,我认为你的tap功能只能返回NULL。
To modify an event, there are various CGEventSet... functions. To kill the event, I think your tap function can just return NULL.
事件类型的枚举包括 kCGEventFlagsChanged = NX_FLAGSCHANGED
。如果您查找IOKit / hidsystem / IOLLEvent.h,则将NX_FLAGSCHANGED定义为12。
The enumeration for event types includes kCGEventFlagsChanged = NX_FLAGSCHANGED
. If you look up IOKit/hidsystem/IOLLEvent.h, it defines NX_FLAGSCHANGED to be 12.
这篇关于OSX Quartz事件抽头:事件类型以及如何编辑事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!