int main(int argc, char **argv) { if(CheckArguments(argc, argv)) return 0; KwmInit(); KWMMach.EventMask = ((1 << kCGEventKeyDown) | (1 << kCGEventKeyUp) | (1 << kCGEventMouseMoved)); KWMMach.EventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, KWMMach.EventMask, CGEventCallback, NULL); if(!KWMMach.EventTap || !CGEventTapIsEnabled(KWMMach.EventTap)) Fatal("ERROR: Could not create event-tap!"); CFRunLoopAddSource(CFRunLoopGetMain(), CFMachPortCreateRunLoopSource(kCFAllocatorDefault, KWMMach.EventTap, 0), kCFRunLoopCommonModes); CGEventTapEnable(KWMMach.EventTap, true); CreateWorkspaceWatcher(KWMMach.WorkspaceWatcher); // NOTE(koekeishiya): Initialize AXLIB // AXLibInit(&AXApplications); // AXLibRunningApplications(); NSApplicationLoad(); CFRunLoopRun(); return 0; }
CGEventRef MouseEventTool::myCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) { if (type == kCGEventTapDisabledByTimeout || type == kCGEventTapDisabledByUserInput) { if (eventTap_) { if (!CGEventTapIsEnabled(eventTap_)) { CGEventTapEnable(eventTap_, true); } } } else if (myself->HandleMouseEvent(type, event)) { // The event was handled, so return NULL saying it should get eaten. return NULL; } // We must return the event for it to be useful. return event; }
internal inline void ConfigureRunLoop() { KWMMach.EventMask = ((1 << kCGEventMouseMoved) | (1 << kCGEventLeftMouseDragged) | (1 << kCGEventLeftMouseDown) | (1 << kCGEventLeftMouseUp) | (1 << kCGEventRightMouseDragged) | (1 << kCGEventRightMouseDown) | (1 << kCGEventRightMouseUp)); KWMMach.EventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, KWMMach.EventMask, CGEventCallback, NULL); if(!KWMMach.EventTap || !CGEventTapIsEnabled(KWMMach.EventTap)) Fatal("Error: Could not create event-tap!"); CFRunLoopAddSource(CFRunLoopGetMain(), CFMachPortCreateRunLoopSource(kCFAllocatorDefault, KWMMach.EventTap, 0), kCFRunLoopCommonModes); }
int main(int argc, char **argv) { detect_window_below_cursor(); CFMachPortRef event_tap; CGEventMask event_mask; CFRunLoopSourceRef run_loop_source; event_mask = ((1 << kCGEventKeyDown) | (1 << kCGEventKeyUp) | (1 << kCGEventMouseMoved)); event_tap = CGEventTapCreate( kCGSessionEventTap, kCGHeadInsertEventTap, 0, event_mask, cgevent_callback, NULL); if(event_tap && CGEventTapIsEnabled(event_tap)) std::cout << "tapping keys.." << std::endl; else fatal("could not tap keys, try running as root"); run_loop_source = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, event_tap, 0); CFRunLoopAddSource(CFRunLoopGetCurrent(), run_loop_source, kCFRunLoopCommonModes); CGEventTapEnable(event_tap, true); CFRunLoopRun(); return 0; }