OS X上的多只鼠标 [英] Multiple mice on OS X

查看:43
本文介绍了OS X上的多只鼠标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发OS X应用程序,该应用程序应该从两只鼠标中获取输入.我想独立阅读每只鼠标的运动.最好的方法是什么?

I am developing an OS X application that is supposed to take input from two mice. I want to read the motion of each mouse independently. What would be the best way to do this?

如果不可能,是否可以通过编程方式禁用/启用任何一只鼠标?

If that is not possible, is there a way to disable/enable either of the mice programmatically?

推荐答案

HID类设备接口绝对是您所需要的.基本上有两个步骤:

The HID Class Device Interface is definitely what you need. There are basically two steps:

首先,您需要找到鼠标设备.为此,您需要构造一个匹配的字典,然后使用它搜索IO Registry.有一些示例代码此处,您将需要在字典中添加一些其他元素,以便只获取鼠标,而不是系统上的所有HID设备.这样的事情应该可以解决问题:

First you need to find the mouse devices. To do this you need to construct a matching dictionary and then search the IO Registry with it. There is some sample code here, you will need to add some additional elements to the dictionary so you just get the mice instead of the all HID devices on the system. Something like this should do the trick:

// 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 );

然后,您需要从上面找到的设备上收听X/Y/button队列.此

You then need to listen to the X/Y/button queues from the devices you found above. This sample code should point you in the right direction. Using the callbacks is much more efficient than polling!

HID代码看起来比实际要复杂得多-它被制成为罗word"的字样.通过CF的东西.

The HID code looks much more complex than it is - it's made rather "wordy" by the CF stuff.

这篇关于OS X上的多只鼠标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆