我正在寻找一种方法来确定运行我的游戏的 Mac 是否连接了多个鼠标。典型的现实示例是连接了外部鼠标的 MacBook(带有内置触控板)。
我的游戏对常见配置有不同的控制设置,例如键盘+鼠标、仅键盘(例如,只有触控板,没有鼠标的 MacBook)和游戏 handle 。理想情况下,我能够在游戏中检测到这一点并相应地设置控件。
我计划支持 Mac OS 10.7+。
我可以使用 Cocoa(或非 Cocoa)API 来获取此信息吗?
作为引用,我已经询问(并得到了答案)similar question适用于基于 Windows 的计算机。
最佳答案
您应该处理 IOKit...以下示例枚举了连接到系统的所有 USB 设备,您可以使用它来查看是否连接了指点设备:
#include <IOKit/IOKitLib.h>
#include <IOKit/usb/IOUSBLib.h>
int main(int argc, const char *argv[])
{
CFMutableDictionaryRef matchingDict;
io_iterator_t iter;
kern_return_t kr;
io_service device;
/* set up a matching dictionary for the class */
matchingDict = IOServiceMatching(kIOUSBDeviceClassName);
if (matchingDict == NULL)
{
return -1; // fail
}
/* Now we have a dictionary, get an iterator.*/
kr = IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDict, &iter);
if (kr != KERN_SUCCESS)
{
return -1;
}
/* iterate */
while ((device = IOIteratorNext(iter)))
{
/* do something with device, eg. check properties */
/* ... */
/* And free the reference taken before continuing to the next item */
IOObjectRelease(device);
}
/* Done, release the iterator */
IOObjectRelase(iter);
return 0;
}
内部触控板应被视为连接的 USB 设备,但我不确定......
关于macos - 有没有办法确定 Mac 是否连接了多个鼠标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23017879/