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的东西。