English 中文(简体)
在OS X上使用多个鼠标
原标题:
  • 时间:2009-05-12 18:34:24
  •  标签:

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类设备接口绝对是您所需的。基本上有两个步骤:

首先你需要找到鼠标设备。要做到这一点,你需要建立一个字典,然后搜索匹配IO注册表。这里有一些示例代码,您将需要一些额外的元素添加到字典,所以你把老鼠而不是系统上所有藏设备。这样应该是可以奏效的:

// 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 /按钮队列从上面的设备你发现。这个示例代码应该你在正确的方向上。使用回调函数比轮询更有效!

隐藏的代码看起来要比这复杂得多——它年代,而“冗长”CF的东西。

问题回答

看起来藏经理是你寻找的东西。

你想要查看的I / O设备,藏东西(人机接口设备)经理。

藏经理是I / O设备的一部分,所以调查有可能是有用的。有两个隐藏管理API,年长的API是一个更痛苦的,然后你有新的10.5及以上的API更舒适。

重要的是要理解的是这是t可能只是一个权宜之计,可能需要一些使其运行的重要工作。如果你可以假设你安装了10.5或更好,使用豹API肯定会有所帮助。

也;取决于你如何完成你做什么,可能是重要的对你隐藏鼠标光标随着它可能仍然很多,即使你收到的信息从老鼠。如果您的应用程序抓取屏幕,我使用CoreGraphics禁用鼠标和画我自己。

你也可以考虑为其中一个找到一个包装器api,可以找到一个例子在这个问题。

除非你能强迫一个老鼠不会处理老鼠,都将继续控制指针。不过,您可以使用IOKit编写一个定制的USB HID驱动程序允许应用程序读取一个或两个老鼠(尽管这可能会干扰使用它们作为正常小鼠)。为USB设备构建定制的用户客户机驱动程序将是一个好的开始对于如何直接与USB鼠标交互。

You could look at the USB/PS-2 device interrupt. Even if you don t want to rewrite a so called driver, it could be usefull since all the mice send their data through.

你也可以检查这个页面http://multicursor-wm.sourceforge.net/,可以给一些提示

也许年代解决您使用usb - > rsr232转换器,通过读取串口吗?





相关问题
热门标签