Hi。
最近在做一个简单的小东西。需要一个类似遥控器的东西来控制(只需要一个按钮就够了)。没有看到合适的设备就买了一个 ppt 翻页笔,这个东西原理上是一个键盘设备(系统硬件中能查到)。但是按键都是上下左右回车 esc 这种很常用的按键,直接挂全局 hook 太影响日常使用了,所以想请问下有没有什么方法可以挂特定设备的键盘事件吗?
我现在做了一半的尝试是用 windows 的 Raw Input API。还不确定能不能绑定(文档看起来似乎可以),不过查了基本的设备信息之后发现几乎很难从键盘设备中确定哪个才是 USB 无线翻页笔。所以还想问一下有没有 dalao 对这个有什么思路的?
提供一下我现在的 raw input 的设备信息:(拔了再插之后能确定第一个应该是 USB 翻页笔)
Device Name: \\?\HID#VID_0C45&PID_0001&MI_00#7&1fb89849&0&0000#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}
Keyboard Mode: 1
Number of function keys: 12
Number of indicators: 3
Number of keys total: 113
Type of the keyboard: 81
Subtype of the keyboard: 0
***********************
Device Name: \\?\HID#Vid_044E&Pid_1212&Col01&Col04#7&332e480d&0&0003#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}
Keyboard Mode: 1
Number of function keys: 12
Number of indicators: 3
Number of keys total: 126
Type of the keyboard: 81
Subtype of the keyboard: 0
***********************
Device Name: \\?\ACPI#HPQ8002#4&1b90ff16&0#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}
Keyboard Mode: 1
Number of function keys: 12
Number of indicators: 3
Number of keys total: 101
Type of the keyboard: 7
Subtype of the keyboard: 0
***********************
通过注册表查第一个设备的注册信息是这样的:(跟普通键盘似乎没太大差别,不知道应该如何区分出来)
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\HID\VID_0C45&PID_0001&MI_00\7&1fb89849&0&0000]
"Capabilities"=dword:000000a0
"Address"=dword:00000001
"ContainerID"="{f647f2cf-5224-11e8-bb2a-bca8a6b927d7}"
"HardwareID"=hex(7):48,00,49,00,44,00,5c,00,56,00,49,00,44,00,5f,00,30,00,43,\
00,34,00,35,00,26,00,50,00,49,00,44,00,5f,00,30,00,30,00,30,00,31,00,26,00,\
52,00,45,00,56,00,5f,00,30,00,30,00,30,00,31,00,26,00,4d,00,49,00,5f,00,30,\
00,30,00,00,00,48,00,49,00,44,00,5c,00,56,00,49,00,44,00,5f,00,30,00,43,00,\
34,00,35,00,26,00,50,00,49,00,44,00,5f,00,30,00,30,00,30,00,31,00,26,00,4d,\
00,49,00,5f,00,30,00,30,00,00,00,48,00,49,00,44,00,5c,00,56,00,49,00,44,00,\
5f,00,30,00,43,00,34,00,35,00,26,00,55,00,50,00,3a,00,30,00,30,00,30,00,31,\
00,5f,00,55,00,3a,00,30,00,30,00,30,00,36,00,00,00,48,00,49,00,44,00,5f,00,\
44,00,45,00,56,00,49,00,43,00,45,00,5f,00,53,00,59,00,53,00,54,00,45,00,4d,\
00,5f,00,4b,00,45,00,59,00,42,00,4f,00,41,00,52,00,44,00,00,00,48,00,49,00,\
44,00,5f,00,44,00,45,00,56,00,49,00,43,00,45,00,5f,00,55,00,50,00,3a,00,30,\
00,30,00,30,00,31,00,5f,00,55,00,3a,00,30,00,30,00,30,00,36,00,00,00,48,00,\
49,00,44,00,5f,00,44,00,45,00,56,00,49,00,43,00,45,00,00,00,00,00
"CompatibleIDs"=hex(7):00,00,00,00
"ClassGUID"="{4d36e96b-e325-11ce-bfc1-08002be10318}"
"Service"="kbdhid"
"DeviceDesc"="@keyboard.inf,%hid.keyboarddevice%;HID Keyboard Device"
"Driver"="{4d36e96b-e325-11ce-bfc1-08002be10318}\\0005"
"Mfg"="@keyboard.inf,%std-keyboards%;(Standard keyboards)"
"ConfigFlags"=dword:00000000
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\HID\VID_0C45&PID_0001&MI_00\7&1fb89849&0&0000\Device Parameters]
(实际上。。哪怕只区分设备来自 usb 我也很知足了。。)
1
ysc3839 2018-05-13 15:37:29 +08:00
你前面的 “ raw input 的设备信息” 是用什么代码获取的?
|
2
ysc3839 2018-05-13 15:47:48 +08:00
另外,可以试试 WinUSB/libusb 直接跟键盘 (USB 翻页笔) 通信。
|
3
ysc3839 2018-05-13 15:51:58 +08:00
进一步搜索发现,可以使用 HID API 这个库来访问 HID 设备。http://www.signal11.us/oss/hidapi/
|
4
pheyx 2018-05-13 15:59:22 +08:00 via iPad
devicename 里有 vendor id 和 product id,可以区分出特定设备。
|
5
vmebeh 2018-05-13 16:25:56 +08:00 via iPhone
|