为什么 HID 在 mac 枚举苹果内置键盘/触控板 3 次
Why HID in mac enumerating Apple Internal Keyboard / Trackpad 3 times?
如标题中所述,当执行hid程序以枚举所有hid设备时,它会打印Apple Internal Keyboard / Trackpad
3次。我已经连接了外部键盘并仅显示了 1 次,这是为什么?
法典:
#include <IOKit/hid/IOHIDLib.h>
/*
MAIN()
------
*/
int main(void)
{
IOHIDManagerRef hid_manager;
char string_buffer[1024];
CFIndex number_of_devices;
CFSetRef device_set;
const IOHIDDeviceRef *device_array;
const IOHIDDeviceRef *current;
CFNumberRef vendor, product;
long vendor_id, product_id;
CFStringRef manufacturer, product_name;
/*
Get a handle to the HID manager
*/
hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
/*
Enumerate all HID devices and count how many we have.
*/
IOHIDManagerSetDeviceMatching(hid_manager, NULL);
IOHIDManagerOpen(hid_manager, kIOHIDOptionsTypeNone);
device_set = IOHIDManagerCopyDevices(hid_manager);
number_of_devices = device_set == NULL ? 0 : CFSetGetCount(device_set);
/*
Tell the user how many we found
*/
if (number_of_devices == 0)
printf("No HID devices detectedn");
else
{
printf("%lld HID devices foundn", (long long)number_of_devices);
/*
Get the list into a C++ array
*/
device_array = new IOHIDDeviceRef [number_of_devices];
CFSetGetValues(device_set, (const void **)device_array);
/*
Iterate the device list
*/
for (current = device_array; current < device_array + number_of_devices; current++)
{
vendor_id = product_id = 0;
/*
Get the vendor ID (which is a 32-bit integer)
*/
if ((vendor = (CFNumberRef)IOHIDDeviceGetProperty(*current, CFSTR(kIOHIDVendorIDKey))) != NULL)
CFNumberGetValue(vendor, kCFNumberSInt32Type, &vendor_id);
printf("VID:%04lX ", vendor_id);
/*
Get the product ID (which is a 32-bit integer)
*/
if ((product = (CFNumberRef)IOHIDDeviceGetProperty(*current, CFSTR(kIOHIDProductIDKey))) != NULL)
CFNumberGetValue((CFNumberRef)product, kCFNumberSInt32Type, &product_id);
printf("PID:%04lX ", product_id);
/*
Get the manufacturer name (which is a string)
*/
if ((manufacturer = (CFStringRef)IOHIDDeviceGetProperty(*current, CFSTR(kIOHIDManufacturerKey)))!= NULL)
{
CFStringGetCString(manufacturer, string_buffer, sizeof(string_buffer), kCFStringEncodingUTF8);
printf("%s ", string_buffer);
}
/*
Get the product name (which is a string)
*/
if ((product_name = (CFStringRef)IOHIDDeviceGetProperty(*current, CFSTR(kIOHIDProductKey))) != NULL)
{
CFStringGetCString(product_name, string_buffer, sizeof(string_buffer), kCFStringEncodingUTF8);
printf("(%s)", string_buffer);
}
puts("");
}
/*
We're finished with the device set and device list so free them.
*/
CFRelease(device_set);
delete [] device_array;
}
return 0;
}
输出:
4 HID devices found
VID:413C PID:2107 Dell (Dell USB Entry Keyboard)
VID:05AC PID:0259 Apple Inc. (Apple Internal Keyboard / Trackpad)
VID:05AC PID:0259 Apple Inc. (Apple Internal Keyboard / Trackpad)
VID:05AC PID:0259 Apple Inc. (Apple Internal Keyboard / Trackpad)
当您检查所有设备的路径时,您将看到差异。
Device Found type: 05ac 0262 path: IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/XHC1@14/XHC1@14000000/HS12@14400000/Apple Internal Keyboard / Trackpad@14400000/Apple Internal Keyboard@0/AppleUSBTCKeyboard@14400000,0 serial_number: Manufacturer: Apple Inc. Product: Apple Internal Keyboard / Trackpad Release: 225 Interface: -1
Device Found type: 05ac 0262 path: IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/XHC1@14/XHC1@14000000/HS12@14400000/Apple Internal Keyboard / Trackpad@14400000/Touchpad@2/AppleUSBTCButtons@14400000,2 serial_number: Manufacturer: Apple Inc. Product: Apple Internal Keyboard / Trackpad Release: 225 Interface: -1
Device Found type: 05ac 0262 path: IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/XHC1@14/XHC1@14000000/HS12@14400000/Apple Internal Keyboard / Trackpad@14400000/Touchpad@1/AppleUSBMultitouchDriver@14400000,1 serial_number: Manufacturer: Apple Inc. Product: Apple Internal Keyboard / Trackpad Release: 225 Interface: -1
因此,当您检查路径时,它们都不同。同样在路径中,您将在最后看到它的用途。
- 内置函数可查看CPP中的成员变量
- 是否有内置方法可以强制转换为不同的基础类型,但保留常量限定符?
- 按字母顺序对字符串中的字母进行排序,而无需使用内置的 sort()
- 将字符串转换为浮点数或整数,而无需使用内置函数(如 atoi 或 atof)
- 如何从 c++ 中类中内置的数组继承
- 如何捕获 C++ 内置异常对象
- macOS 是内置在 clang 编译器中还是内置于 xcode ide 中?
- 将编译器开关添加到 Eclipse CDT 内置编译器设置生成?
- gcc Atomic在gcc 4.1.1中内置了奇怪的行为
- 是否有用于元素部分移位的 simd 指令/内在/内置指令?
- 何时包含内置类型和运算符的标头?
- 基本类型与内置类型有什么区别C++
- 指内置类型的文字
- GLUT 问题:重新声明 c++ 内置类型'wchar_t'时出错
- 像自定义类一样构造的指针(内置类型)如何工作?
- 内置类型与用户定义的类型 C++
- 将内置类型变量传递给只有一个类类型参数的"+"运算符函数时自动类型转换的构造函数
- C++内置类型的基于类型的调度
- 在不使用内置库函数的情况下添加字符串,我做错了什么?
- 为什么 HID 在 mac 枚举苹果内置键盘/触控板 3 次