Created
September 29, 2010 18:10
-
-
Save mkrautz/603213 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcc eventtap.c -o eventtap -framework ApplicationServices -framework CoreFoundation | |
#include <CoreFoundation/CoreFoundation.h> | |
#include <ApplicationServices/ApplicationServices.h> | |
static CGEventRef eventtap_callback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *udata) { | |
fprintf(stderr, "callback!\n"); | |
fflush(stderr); | |
return event; | |
} | |
int main(int argc, char *argv[]) { | |
CGEventMask evmask = CGEventMaskBit(kCGEventLeftMouseDown) | | |
CGEventMaskBit(kCGEventLeftMouseUp) | | |
CGEventMaskBit(kCGEventRightMouseDown) | | |
CGEventMaskBit(kCGEventRightMouseUp) | | |
CGEventMaskBit(kCGEventOtherMouseDown) | | |
CGEventMaskBit(kCGEventOtherMouseUp) | | |
CGEventMaskBit(kCGEventKeyDown) | | |
CGEventMaskBit(kCGEventKeyUp) | | |
CGEventMaskBit(kCGEventFlagsChanged) | | |
CGEventMaskBit(kCGEventMouseMoved) | | |
CGEventMaskBit(kCGEventLeftMouseDragged) | | |
CGEventMaskBit(kCGEventRightMouseDragged) | | |
CGEventMaskBit(kCGEventOtherMouseDragged) | | |
CGEventMaskBit(kCGEventScrollWheel); | |
CFMachPortRef port = CGEventTapCreate(kCGSessionEventTap, | |
kCGHeadInsertEventTap, | |
0, evmask, eventtap_callback, NULL); | |
CFRunLoopRef loop = CFRunLoopGetCurrent(); | |
CFRunLoopSourceRef src = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, port, 0); | |
CFRunLoopAddSource(loop, src, kCFRunLoopCommonModes); | |
CFRunLoopRun(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment