Joh*_*ski 17 macos mouse input
我正在开发一个OS X应用程序,它应该从两个鼠标中获取输入.我想独立阅读每只鼠标的动作.最好的方法是什么?
如果那是不可能的,有没有办法以编程方式禁用/启用任一鼠标?
Bid*_*ids 13
HID类设备接口绝对是您所需要的.基本上有两个步骤:
首先,您需要找到鼠标设备.为此,您需要构建匹配的字典,然后使用它搜索IO注册表.有一些示例代码在这里,您将需要一些额外的元素添加到字典中,所以你刚才得到的小鼠,而不是在系统上的所有HID设备.像这样的东西应该做的伎俩:
// Set up a matching dictionary to search the I/O Registry by class
// name for all HID class devices`
hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey);
// Add key for device usage page - 0x01 for "Generic Desktop"
UInt32 usagePage = 0x01;
CFNumberRef usagePageRef = ::CFNumberCreate( kCFAllocatorDefault, kCFNumberLongType, &usagePage );
::CFDictionarySetValue( hidMatchDictionary, CFSTR( kIOHIDPrimaryUsagePageKey ), usagePageRef );
::CFRelease( usagePageRef );
// Add key for device usage - 0x02 for "Mouse"
UInt32 usage = 0x02;
CFNumberRef usageRef = ::CFNumberCreate( kCFAllocatorDefault, kCFNumberLongType, &usage );
::CFDictionarySetValue( hidMatchDictionary, CFSTR( kIOHIDPrimaryUsageKey ), usageRef );
::CFRelease( usageRef );
Run Code Online (Sandbox Code Playgroud)
然后,您需要从上面找到的设备中收听X/Y /按钮队列.此示例代码应指向正确的方向.使用回调比轮询更有效!
HID代码看起来比它复杂得多 - 它被CF的东西变得相当"冗长".
| 归档时间: |
|
| 查看次数: |
5183 次 |
| 最近记录: |