I am trying to handle events with core graphics and core fundation on mac os.
My code:
#import
#import
static int counter = 0;
CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) {
printf("event 0x%i\n ", counter++);
return event;
}
int main(int argc, const char * argv[]) {
CFRunLoopRef runner = CFRunLoopGetCurrent();
CFMachPortRef mach = CGEventTapCreate(kCGHIDEventTap,kCGTailAppendEventTap , kCGEventTapOptionDefault, kCGEventMaskForAllEvents, myCGEventCallback, NULL);
CFRunLoopSourceRef runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, mach, 0);
CFRunLoopAddSource(runner, runLoopSource, kCFRunLoopCommonModes);
CGEventTapEnable(mach, true);
CFRunLoopRun();
printf("end\n");
}
But It reacts only for touchpad-events. Keyboard events seems to be ignored by my program. I have tried changing event masks but I does not work. Can you give some advice?
PS
Is that good start to handle events? I want to make full screen OpenGL game
with core graphics without libraries like SFML or SDL.
I am using CGDisplayCapture and CGL to create OpeGL context.