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 我也很知足了。。)
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.