为什么 USB 键盘报告格式无法按照定义的标准工作



我有一个STM32演示板,我试图将其配置为USB键盘。我正在为RTOS主机系统开发它。

这是根据标准的键盘IN报告格式。

`unsigned char hid_report[8];
 hid_report[0]=0xE1;//E1 is scan code for shift modifier key
 hid_report[1]=0x00;//reserved
 hid_report[2]=0x04;//04 is scan code for 'a'/'A'
 hid_report[3]=0x00;
 hid_report[4]=0x00;
 hid_report[5]=0x00;
 hid_report[6]=0x00;
 hid_report[7]=0x00;`

但是如果我将其发送到RTOS主机,系统就会挂起。我在 Windows 上尝试过,但 SHIFT 键似乎不起作用。

另一方面,如果我将报告作为

 unsigned char hid_report[8];
`hid_report[0]=0x00;
 hid_report[1]=0x00;//reserved
 hid_report[2]=0xE1;//E1 is scan code for shift modifier key
 hid_report[3]=0x04;//04 is scan code for 'a'/'A'
 hid_report[4]=0x00;
 hid_report[5]=0x00;
 hid_report[6]=0x00;
 hid_report[7]=0x00;`

在 RTOS 中,它似乎工作正常(正在发送大写字母"A")。但是在Windows SHIFT键仍然不起作用。

任何人都知道为什么它对两个不同的操作系统的行为不同,为什么它没有按照标准工作?

根据 USB HID 文档,尽管为修饰键定义了扫描代码 (E0-E7),但在为修改键保留的报告的第一个字节中使用它们时,它们应作为位图而不是数组数据发送。

因此,不应在键盘报告的第一个字节中发送 E1,而应发送 0x02(0000 0010)。

这解决了问题

最新更新