USB键盘报告描述符数据格式分析
2021-05-07
4303
1
USB键盘的HID报表描述符的内容参见下表。数据的输入端点为中断方式,当有键盘敲击事件时,会上报数据长度为8字节的数据报告。
0x05,0x01,// Global Generic Desktop
0x09,0x06,// Local KeyBoard
0xA1,0x01,// Main app collection
0x05,0x07,// Global KeyBoard
//第1字节
0x19,0xe0,// Local Usage Min (KeyBoard LeftControl)
0x29,0xe7,// Local Usage Max (KeyBoard Right GUI)
0x15,0x00,// Global Logical Min
0x25,0x01,// Global Logical Max
0x95,0x08,// Global ReportCount
0x75,0x01,// Global ReportSize
0x81,0x02,// Main Input(Data,Var,Abs)
//第2字节
0x95,0x01,// Global ReportCount
0x75,0x08,// Global ReportSize
0x81,0x03,// Main Input(Cnst,Var,Abs)
//第3-8字节
0x95,0x06,// Global ReportCount
0x75,0x08,// Global ReportSize
0x15,0x00,// Global Logical Min
0x26,0xff,0x00,//Global Logical Max
0x19,0x00,// Local Usage Min
0x29,0x65,// Local Usage Max
0x81,0x00,// Main Output(Data,Ary,Abs)
//1字节输出报告
0x15,0x00,// Global Logical Min
0x25,0x01,// Global Logical Max
0x95,0x05,// Global ReportCount
0x75,0x01,// Global ReportSize
0x05,0x08,// Global LED
0x19,0x01,// Local Usage Min
0x29,0x05,// Local Usage Max
0x91,0x02,// Main Output(Data,Var,Abs)
//补足上面变成1个字节
0x95,0x01,// Global ReportCount
0x75,0x03,// Global ReportSize
0x91,0x03,// Main Output(Cnst,Var,Abs)
0xc0 // Main End collection
键盘的描述符共有8字节的输入报告和1字节的输出报告。
1字节的输出报告输出报告
如果不给键盘配置OUT端点,那么键盘的1字节输出报告将由控制端点的SetReport进行传输。
1字节输出报告:这1个字节总共用了5bits使用3bits常量来补足成1个字节。5bits用来点亮特殊键盘上的Led灯,比如键盘的大小写,数字键,小键盘的LED灯。
8字节的输入报告
数据报告8个字节的含义见下表:
Byte | Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 |
---|---|---|---|---|---|---|---|---|
0 | RightGUI | RightAlt | RightShift | RightControl | LeftGUI | LeftAlt | LeftShift | LeftControl |
1 | Reserved | |||||||
2 | Keyboard Page Usage | |||||||
3 | Keyboard Page Usage | |||||||
4 | Keyboard Page Usage | |||||||
5 | Keyboard Page Usage | |||||||
6 | Keyboard Page Usage | |||||||
7 | Keyboard Page Usage |
- Byte0各位则表示左右GUI(win),alt,shift,control键是否按下,按下为1。
- Byte1是保留字节,
- 其6个字节表示此时按下的其他所有键盘按键的键码,从低到高填充,没按就是0x00.如果同时按下的键超过允许,则显示0xff
Byte0各位则表示左右GUI(win),alt,shift,control键是否按下,按下为1。
键码含义可参照《HID Usage Tables》Version 1.11第53页中的K10 eyboard/Keypad Page。
附Keyboard Page Usage
文档HID Usage Tables详见:https://d1.amobbs.com/bbs_upload782111/files_47/ourdev_692986N5FAHU.pdf
#define KB_ERROR 0x01
#define KB_A 0x04
#define KB_B 0x05
#define KB_C 0x06
#define KB_D 0x07
#define KB_E 0x08
#define KB_F 0x09
#define KB_G 0x0A
#define KB_H 0x0B
#define KB_I 0x0C
#define KB_J 0x0D
#define KB_K 0x0E
#define KB_L 0x0F
#define KB_M 0x10
#define KB_N 0x11
#define KB_O 0x12
#define KB_P 0x13
#define KB_Q 0x14
#define KB_R 0x15
#define KB_S 0x16
#define KB_T 0x17
#define KB_U 0x18
#define KB_V 0x19
#define KB_W 0x1A
#define KB_X 0x1B
#define KB_Y 0x1C
#define KB_Z 0x1D
#define KB_1 0x1E
#define KB_2 0x1F
#define KB_3 0x20
#define KB_4 0x21
#define KB_5 0x22
#define KB_6 0x23
#define KB_7 0x24
#define KB_8 0x25
#define KB_9 0x26
#define KB_0 0x27
#define KB_ENTER 0x28
#define KB_ESC 0x29
#define KB_BACKSPACE 0x2A
#define KB_TAB 0x2B
#define KB_SPACE 0x2C
#define KB_MIUS 0x2D //-_
#define KB_EQUAL 0x2E //=+
#define KB_LSQUBRACKET 0x2F //[{
#define KB_RSQUBRACKET 0x30 //]}
#define KB_BACKSLASH 0x31 //\|
#define KB_SEMICOLON 0x33 //;:
#define KB_APOSTROPHE 0x34 //'"
#define KB_TILDE 0x35 //`~
#define KB_COMMA 0x36 //,<
#define KB_FULLSTOP 0x37 //.>
#define KB_SLASH 0x38 ///?
#define KB_CAPSLOCK 0x39
#define KB_F1 0x3A
#define KB_F2 0x3B
#define KB_F3 0x3C
#define KB_F4 0x3D
#define KB_F5 0x3E
#define KB_F6 0x3F
#define KB_F7 0x40
#define KB_F8 0x41
#define KB_F9 0x42
#define KB_F10 0x43
#define KB_F11 0x44
#define KB_F12 0x45
#define KB_PRTSCR 0x46
#define KB_SCOLLLOCK 0x47
#define KB_PAUSE 0x48
#define KB_INSERT 0x49
#define KB_HOME 0x4A
#define KB_PAGEUP 0x4B
#define KB_DELETE 0x4C
#define KB_END 0x4D
#define KB_PAGEDOWN 0x4E
#define KB_RARROW 0x4F
#define KB_LARROW 0x50
#define KB_DARROW 0x51
#define KB_UARROW 0x52
#define KB_NUMLOCK 0x53
#define KB_PAD_DIV 0x54 ///
#define KB_PAD_MUL 0x55 //*
#define KB_PAD_MINUS 0x56 //-
#define KB_PAD_PLUS 0x57 //+
#define KB_PAD_ENTER 0x58
#define KB_PAD_1 0x59
#define KB_PAD_2 0x5A
#define KB_PAD_3 0x5B
#define KB_PAD_4 0x5C
#define KB_PAD_5 0x5D
#define KB_PAD_6 0x5E
#define KB_PAD_7 0x5F
#define KB_PAD_8 0x60
#define KB_PAD_9 0x61
#define KB_PAD_0 0x62
#define KB_PAD_DEL 0x63
#define KB_APPLICATION 0x65 //RWin右边键
...
HID人机交互QQ群:564808376
UAC音频QQ群:218581009
UVC相机QQ群:331552032
BOT&UASP大容量存储QQ群:258159197
STC-USB单片机QQ群:315457461
USB技术交流QQ群2:580684376
USB技术交流QQ群:952873936