Quartz OSX Event Markers: Event Types and Event Editing Methods

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 ??

+5
source share
1 answer

To change an event, there are various CGEventSet functions .... To kill an event, I think your tap function can just return NULL.

Enumeration for event types includes kCGEventFlagsChanged = NX_FLAGSCHANGED . If you are looking for IOKit / hidsystem / IOLLEvent.h, it sets NX_FLAGSCHANGED to 12.

+2
source

Source: https://habr.com/ru/post/987456/


All Articles