17 #if defined(__APPLE__) && !defined(CPPPARSER) 24 IOKitInputDeviceManager::
25 IOKitInputDeviceManager() {
26 _hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
29 <<
"Failed to create an IOHIDManager.\n";
34 int page = kHIDPage_GenericDesktop;
35 int usages[] = {kHIDUsage_GD_GamePad,
36 kHIDUsage_GD_Joystick,
38 kHIDUsage_GD_Keyboard,
39 kHIDUsage_GD_MultiAxisController, 0};
44 CFMutableArrayRef match = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
47 CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
48 CFNumberRef page_ref = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page);
49 CFDictionarySetValue(dict, CFSTR(kIOHIDDeviceUsagePageKey), page_ref);
51 CFNumberRef usage_ref = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, usage);
52 CFDictionarySetValue(dict, CFSTR(kIOHIDDeviceUsageKey), usage_ref);
54 CFArrayAppendValue(match, dict);
58 IOHIDManagerSetDeviceMatchingMultiple(_hid_manager, match);
61 IOHIDManagerRegisterDeviceMatchingCallback(_hid_manager, on_match_device,
this);
62 IOHIDManagerScheduleWithRunLoop(_hid_manager, CFRunLoopGetMain(), kCFRunLoopCommonModes);
63 IOHIDManagerOpen(_hid_manager, kIOHIDOptionsTypeNone);
69 IOKitInputDeviceManager::
70 ~IOKitInputDeviceManager() {
71 IOHIDManagerUnscheduleFromRunLoop(_hid_manager, CFRunLoopGetMain(), kCFRunLoopCommonModes);
72 IOHIDManagerClose(_hid_manager, kIOHIDOptionsTypeNone);
73 CFRelease(_hid_manager);
79 void IOKitInputDeviceManager::
80 on_match_device(
void *ctx, IOReturn result,
void *sender, IOHIDDeviceRef device) {
82 nassertv(mgr !=
nullptr);
85 PT(
InputDevice) input_device =
new IOKitInputDevice(device);
86 if (device_cat.is_debug()) {
88 <<
"Discovered input device " << *input_device <<
"\n";