-
-
Save yamaya/7dcb831bb54072bab14821d163793d7c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <IOKit/hid/IOHIDLib.h> | |
#include <IOKit/hidsystem/event_status_driver.h> | |
static int hid_mousex, hid_mousey; | |
static void hidCallback(void* context, IOReturn result, void* sender, IOHIDValueRef valueRef) | |
{ | |
IOHIDElementRef element = IOHIDValueGetElement(valueRef); | |
if (mouse_capture > 0 && IOHIDElementGetUsagePage(element) == kHIDPage_GenericDesktop) { | |
int value = (int)IOHIDValueGetIntegerValue(valueRef); | |
switch (IOHIDElementGetUsage(element)) { | |
case kHIDUsage_GD_X: | |
hid_mousex += value; | |
break; | |
case kHIDUsage_GD_Y: | |
hid_mousey += value; | |
break; | |
} | |
} | |
} | |
... init ... | |
sys_log(SYSLOG_NONE, "Initializing the HID manager"); | |
hidManager = IOHIDManagerCreate(kCFAllocatorSystemDefault, kIOHIDOptionsTypeNone); | |
if (!hidManager) { | |
sys_log(SYSLOG_FATAL, "Failed to initialize the HID manager"); | |
eng_shutdown(); | |
return 0; | |
} | |
sys_log(SYSLOG_NONE, "Initializing the HID callbacks"); | |
IOHIDManagerSetDeviceMatching(hidManager, NULL); | |
IOHIDManagerRegisterInputValueCallback(hidManager, hidCallback, NULL); | |
IOHIDManagerScheduleWithRunLoop(hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); | |
if (IOHIDManagerOpen(hidManager, kIOHIDOptionsTypeNone) != kIOReturnSuccess) { | |
sys_log(SYSLOG_FATAL, "Failed to open the HID manager"); | |
eng_shutdown(); | |
return 0; | |
} | |
... shutdown ... | |
IOHIDManagerUnscheduleFromRunLoop(hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); | |
CFRelease(hidManager); | |
... main loop ... | |
if (hid_mousex) { | |
eng_key(KEY_MOUSE_X, hid_mousex); | |
hid_mousex = 0; | |
} | |
if (hid_mousey) { | |
eng_key(KEY_MOUSE_Y, hid_mousey); | |
hid_mousey = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment