8120年了,USB键盘还只能6键无冲?

您所在的位置:网站首页 键盘全键无冲和6键无冲的区别 8120年了,USB键盘还只能6键无冲?

8120年了,USB键盘还只能6键无冲?

2024-07-11 14:07| 来源: 网络整理| 查看: 265

标题在放屁!

    今天群里有人跟我讲,USB-HID协议中规定了键盘只能以8字节方式与计算机通信,且只要后6个字节表示键码。这我当场就不行了啊!多少我也是做过键盘,看过HID协议的人,凭什么你就把人HID协议打成只能6键无冲了呢!那这就得科普一下了!

USB只能六键无冲的来源

    我们从头说起,为什么很多人以为USB接口只能实现6键无冲(包括做键盘以前的我)。

百度……

    大家都以为,USB-HID协议限制了USB只能一次发出6个普通按键和那几个(忘记几个了)修饰键。所以全键无冲的实现方法,就是每6个按键模拟成一个键盘,这样就可以全键无冲啦!真好,继任务管理器数框框以后,又出现了设备管理器数键盘的游戏。

    事实上呢,HID协议确实规定了键盘应当按照下图的定义来发送键码,但是这样做的目的是为了让BIOS可以识别键盘正常工作(大概内容,以下原文,我英语差)

HID 1.11规范

The HID Subclass 1 defines two descriptors for Boot Devices. Devices may append additional data to these boot reports, but the first 8 bytes of keyboard reports and the first 3 bytes of mouse reports must conform to the format defined by the Boot Report descriptor in order for the data to be correctly interpreted by the BIOS. The report may not exceed 8 bytes in length. The BIOS will ignore any extensions to reports. These descriptors describe reports that the BIOS expects to see. However, since the BIOS does not actually read the Report descriptors, these descriptors do not have to be hard-coded into the device if an alternative report descriptor is provided. Instead, descriptors that describe the device reports in a USB-aware operating system should be included (these may or may not be the same). When the HID class driver is loaded, it will issue a Change Protocol, changing from the boot protocol to the report protocol after reading the boot interface’s Report descriptor.

引用自HID 1.11规范文档:https://www.usb.org/sites/default/files/documents/hid1_11.pdf

当我开始做键盘

    这都8102年了,USB还只能6键无冲么?那么多大厂键盘都是全键无冲了(吹一波封面),我怎么能落后呢,搜索一下!

USB keyboards use the HID spec.  HID rides on top of USB and defines a set of data structures, protocol, and predefined input lists that can be used to implement just about any type of user input device without requiring special drivers.

Within the USB HID spec are some predefined input types that are strictly controlled on how they can act.  This allows small softwares such as your PC's BIOS to be able to use these input types without much complicated code.  One of them is the BOOT-compatible keyboard.  The BOOT-compatible keyboard must always send 8-byte packets.  These packets only leave room for 6 bytes to contain scancodes.  That's where the 6KRO comes from.

Once you are in windows, though, your device is allowed to redefine its input pattern.  My keyboards redefine their HID template to include a large bitfield (16 bytes) that encodes up to 128 keys, thus allowing NKRO.

引用自:https://geekhack.org/index.php?topic=62296.0

大意就是说:

    USB键盘使用HID规范。 HID位于USB之上,定义了一组数据结构,协议和预定义输入列表,可用于实现几乎任何类型的用户输入设备,而无需特殊驱动程序。

    在USB HID规范中是一些预定义的输入类型,严格控制它们的行为方式。 这允许小型软件(如PC的BIOS)能够使用这些输入类型而无需复杂的代码。 其中一个是启动兼容键盘。 启动兼容键盘必须始终发送8字节数据包。 这些数据包只留下6个字节的空间来包含扫描码。 这就是六键无冲的来源。

    但是,一旦进入Windows,您的设备就可以重新定义其输入模式。 他的键盘重新定义了HID模板,包括一个大的位域(16字节),可以编码多达128个键,从而允许全键无冲。

    哦?也就是说六键无冲一直只是一个误读,实际上我们可以重新定义HID回报的数据来实现全键无冲,而不需要注册多达18个键盘来实现104键的全键无冲咯?答案是肯定的,而且考虑到现在电脑都用UEFI了……大概不兼容BIOS也没什么大问题吧!反正笔记本键盘是PS/2接口的,无所畏惧

最后全键无冲的实现

    我放弃研究HID协议啦!(鼓掌)直接用了前辈做好的全键无冲的库!(开心)

不过这里我们可以对比一下这两种键盘在数据格式上的不同:

6键无冲的BIOS兼容模式

104无冲的模式

总结

标题是在放屁!HID协议从制定起就没有规定必须要用8字节方式回报,8字节只是为了兼容BIOS才使用的,所以从来就没有USB接口只能6键无冲的说法~

厂家的键盘要是没有全键无冲,只能说是他们懒得做,USB不能继续背锅了!

PS:最后放一下我做的键盘

此时电流高达200MA



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3