HID键盘的设备描述符
1 | char ReportDescriptor[63] = { |
HID键盘通过脚本创建
1 |
|
HID键盘数据上报格式
1 | # 字节(BYTE)是计算机数据处理的最小单位,一个字节是八个比特(bit) |
组合键在第一字节的值
BIT 7 | BIT 6 | BIT 5 | BIT 4 | BIT 3 | BIT 2 | BIT 1 | BIT 0 |
---|---|---|---|---|---|---|---|
R_Win | R_Alt | R_Shift | R_Ctrl | L_Win | L_Alt | L_Shift | L_Ctrl |
1 | # 第一个字节(BYTE1)组合按键的值。最右边的是第一个比特(BIT0),左边是尾 右边是头 |
组合按键 | HID码值 (10 [16]进制) | 组合按键 | HID码值 (10 [16]进制) |
---|---|---|---|
L_Ctrl | 1 [0X01] | R_Ctrl | 16 [0X10] |
L_Shift | 2 [0X02] | R_Shift | 32 [0X20] |
L_Alt | 4 [0X04] | R_Alt | 64 [0X40] |
L_Win | 8 [0X08] | R_Win | 128 [0X80] |
部分编程语言操作示例
- Shell下操作示例
1 | # -n:不自动换行 -e:解释转义字符 |
- Python下操作示例
1 | #!/usr/bin/env python3 |
- JavaScript下操作示例
1 |
|
HID键盘输入数据查看
1 | # 首先通过 cat /proc/bus/input/devices 查看各个设备的描述 |
常用HID规范的键盘码
按键名称 | HID码值 (10 [16]进制) | 按键名称 | HID码值 (10 [16]进制) |
---|---|---|---|
A | 4 [0X04] | CapLck | 57 [0X39] |
B | 5 [0X05] | F1 | 58 [0X3A] |
C | 6 [0X06] | F2 | 59 [0X3B] |
D | 7 [0X07] | F3 | 60 [0X3C] |
E | 8 [0X08] | F4 | 61 [0X3D] |
F | 9 [0X09] | F5 | 62 [0X3E] |
G | 10 [0X0A] | F6 | 63 [0X3F] |
H | 11 [0X0B] | F7 | 64 [0X40] |
I | 12 [0X0C] | F8 | 65 [0X41] |
J | 13 [0X0D] | F9 | 66 [0X42] |
K | 14 [0X0E] | F10 | 67 [0X43] |
L | 15 [0X0F] | F11 | 68 [0X44] |
M | 16 [0X10] | F12 | 69 [0X45] |
N | 17 [0X11] | PrintScr | 70 [0X46] |
O | 18 [0X12] | Scroll | 71 [0X47] |
P | 19 [0X13] | Pause | 72 [0X48] |
Q | 20 [0X14] | Insert | 73 [0X49] |
R | 21 [0X15] | Home | 74 [0X4A] |
S | 22 [0X16] | PageUp | 75 [0X4B] |
T | 23 [0X17] | Delete | 76 [0X4C] |
U | 24 [0X18] | End | 77 [0X4D] |
V | 25 [0X19] | PageDn | 78 [0X4E] |
W | 26 [0X1A] | Right | 79 [0X4F] |
X | 27 [0X1B] | Left | 80 [0X50] |
Y | 28 [0X1C] | Down | 81 [0X51] |
Z | 29 [0X1D] | Up | 82 [0X52] |
1 | 30 [0X1E] | NumLock | 83 [0X53] |
2 | 31 [0X1F] | KEYPAD / | 84 [0X54] |
3 | 32 [0X20] | KEYPAD * | 85 [0X55] |
4 | 33 [0X21] | KEYPAD - | 86 [0X56] |
5 | 34 [0X22] | KEYPAD + | 87 [0X57] |
6 | 35 [0X23] | KEYPAD ENTER | 88 [0X58] |
7 | 36 [0X24] | KEYPAD 1 | 89 [0X59] |
8 | 37 [0X25] | KEYPAD 2 | 90 [0X5A] |
9 | 38 [0X26] | KEYPAD 3 | 91 [0X5B] |
0 | 39 [0X27] | KEYPAD 4 | 92 [0X5C] |
Enter | 40 [0X28] | KEYPAD 5 | 93 [0X5D] |
ESC | 41 [0X29] | KEYPAD 6 | 94 [0X5E] |
BackSpace | 42 [0X2A] | KEYPAD 7 | 95 [0X5F] |
Tab | 43 [0X2B] | KEYPAD 8 | 96 [0X60] |
Space | 44 [0X2C] | KEYPAD 9 | 97 [0X61] |
- | 45 [0X2D] | KEYPAD 0 | 98 [0X62] |
= | 46 [0X2E] | KEYPAD . | 99 [0X63] |
[ | 47 [0X2F] | ——– | ——— |
] | 48 [0X30] | ——– | ——— |
\ | 49 [0X31] | LCtrl | 224 [0XE0] |
\ | 50 [0X32] | LShift | 225 [0XE1] |
; | 51 [0X33] | LAlt | 226 [0XE2] |
‘ | 52 [0X34] | LWIN | 227 [0XE3] |
` | 53 [0X35] | RCtrl | 228 [0XE4] |
, | 54 [0X36] | RShift | 229 [0XE5] |
. | 55 [0X37] | RAlt | 230 [0XE6] |
/ | 56 [0X38] | RWIN | 231 [0XE7] |