-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestsee.c
38 lines (29 loc) · 1.33 KB
/
testsee.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <ApplicationServices/ApplicationServices.h>
#include <stdio.h>
CGEventRef eventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) {
printf("Event detected! Type: %d\n", type);
return event;
}
int main() {
CGEventMask eventMask = (1 << kCGEventKeyDown) | (1 << kCGEventLeftMouseDown) |
(1 << kCGEventRightMouseDown) | (1 << kCGEventMouseMoved) |
(1 << kCGEventOtherMouseDown);
CFMachPortRef eventTap = CGEventTapCreate(kCGAnnotatedSessionEventTap,
kCGHeadInsertEventTap,
0,
eventMask,
eventCallback,
NULL);
if (!eventTap) {
fprintf(stderr, "Failed to create event tap!\n");
return 1;
}
CFRunLoopSourceRef runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
CGEventTapEnable(eventTap, true);
printf("Event tap created and enabled.\n");
CFRunLoopRun(); // Run the loop to keep capturing events
CFRelease(eventTap);
CFRelease(runLoopSource);
return 0;
}