简体   繁体   English

检测USB HID设备何时模拟键盘的可靠方法

[英]Reliable method for detecting when a USB HID device is emulating a keyboard

I'm working on an embedded system, and I need to determine if the user has connected an HID device emulating a keyboard (ie a barcode scanner) or an actual keyboard. 我正在嵌入式系统上工作,需要确定用户是否已连接模拟键盘(即条形码扫描仪)或实际键盘的HID设备。

I can inspect the iManufacturer, iProduct, iSerialNumber, and iInterface string descriptors to gain some clues. 我可以检查iManufacturer,iProduct,iSerialNumber和iInterface字符串描述符以获取一些线索。 For example, "reader" or "scanner" has been observed to appear in the iProduct string when a barcode reader has been connected. 例如,在连接条形码阅读器后,已观察到“阅读器”或“扫描仪”出现在iProduct字符串中。 Likewise, "emulation" has been seen in the iInterface string. 同样,在iInterface字符串中也看到了“仿真”。 However, I'm a bit reluctant to rely solely on these strings (string case is easy enough to handle, but handling things like abbreviations in key words/phrases quickly becomes onerous.) 但是,我有点不愿仅仅依靠这些字符串(字符串大小写很容易处理,但是处理诸如关键词/短语缩写之类的事情很快就变得繁重。)

I've reviewed the USB 1.10 and 1.11 specs and found that the Report descriptor offers some cues, as well. 我查看了USB 1.10和1.11规范,发现Report描述符也提供了一些提示。 For example, the Global Usage item should be something like 0x0501 for Generic Desktop, and the Local Usage item should be 0x0906 (Keyboard). 例如,对于通用桌面,“全局使用情况”项应类似于0x0501,而“本地使用情况”项应为0x0906(键盘)。 Is there anything else in the Report descriptor that might assist in detecting the difference? 报告描述符中是否还有其他可帮助检测差异的内容?

I would like to avoid relying on the Vendor ID and Product ID lists since this is an embedded system with limited resources. 我想避免依赖供应商ID和产品ID列表,因为这是一个资源有限的嵌入式系统。 Suggestions? 有什么建议吗? Is there something I've missed? 有什么我想念的吗?

There is no absolutely reliable method to do this. 没有绝对可靠的方法来执行此操作。 There cannot be, because there is no absolute definition of what is or is not a keyboard -- nor of what the difference is between "emulating a keyboard" and "being a keyboard". 之所以不可能,是因为没有关于什么是键盘的绝对定义,也没有“模拟键盘”和“成为键盘”之间的区别的绝对定义。 The boundary gets particularly fuzzy around assistive devices and things like chording keyboards, but even beyond that, you have the fundamental problem that the way to emulate a keyboard is to communicate across the USB cable in exactly the way that a keyboard communicates. 辅助设备和和弦键盘之类的边界变得特别模糊,但即使如此,您仍然存在一个基本问题,即模拟键盘的方法就是通过USB电缆以与键盘通信完全相同的方式进行通信。

The methods you've suggested are reasonable heuristics for identifying a number of things that are clearly non-keyboards (with a faint risk of false positives in some cases), but heuristics that look for hints are the best solution that's going to be possible. 您建议的方法是合理的启发式方法,用于识别许多显然不是键盘的事物(在某些情况下,存在误报的微弱风险),但是寻找提示的启发式方法将是可能的最佳解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM