keyboard - 为什么 USB 键盘报告格式不按照定义的标准工作?

标签 keyboard usb stm32

我有一个 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/

相关文章:

lua - 用Lua模拟键盘输入

python - 如何用Python同时记录鼠标和键盘的移动?

macos - 操作系统 X : Capture keyboard input without visually taking focus

android - TimePicker 小部件未获取当前时间

android 手机通过 USB 端口安装桌面分区(磁盘级别的反向 USB 网络共享?)

c# - 在 Windows 7 中使用 C++/C#/PowerShell 禁用/启用 USB 驱动程序而无需重新启动

.net - 如何确定USB闪存驱动器制造商?

c++ - ARM 二进制大小

timer - stm32动态定时器设置改变

string - 以字符串形式接收数字(uart)