我有一个 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)。
这解决了问题
关于keyboard - 为什么 USB 键盘报告格式不按照定义的标准工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35014933/