Bit: 7 6 5 4 3 2 1 0
+---+---+---+---+---+---+---+---+
Byte 0 | RG| RA| RS| RC| LG| LA| LS| LC| Modifier bits (LC=Left Control, LS= Left Shift, etc)
+---+---+---+---+---+---+---+---+
Byte 1 | Reserved byte |
+---+---+---+---+---+---+---+---+
Byte 2 | Key 1 |
+---+---+---+---+---+---+---+---+
Byte 3 | Key 2 |
+---+---+---+---+---+---+---+---+
Byte 4 | Key 3 |
+---+---+---+---+---+---+---+---+
Byte 5 | Key 4 |
+---+---+---+---+---+---+---+---+
Byte 6 | Key 5 |
+---+---+---+---+---+---+---+---+
Byte 7 | Key 6 |
+---+---+---+---+---+---+---+---+
每个修饰键都表示为字节 0 中的单个位。要指示按下多个修饰键,您可以将这些值“或”在一起。你可以编写如下代码:
#define MOD_LEFT_CONTROL 0b00000001
#define MOD_LEFT_SHIFT 0b00000010
#define MOD_LEFT_ALT 0b00000100
.
.
#define KEY_R 0x15
.
.
modifiers = MOD_LEFT_CONTROL | MOD_LEFT_SHIFT;
reserved = 0;
key[0] = KEY_R;
可以定义一个 HID 报告描述符,允许将修改键用法包含在 6 字节键数组中,但通常不需要这样做 - 并且上述方案无论如何使用更少的空间。
Hex Binary
LEFT CONTROL 0x01 00000001
LEFT SHIFT 0x02 00000010
LEFT ALT 0x04 00000100
LEFT CMD|WIN 0x08 00001000
RIGHT CONTROL 0x10 00010000
RIGHT SHIFT 0x20 00100000
RIGHT ALT 0x40 01000000
RIGHT CMD|WIN 0x80 10000000
要发送多个修饰符,请合并字节,例如:CONTROL + ALT > 您使用字节:00000101 > 十六进制:0x05
CONTROL + SHIFT + ALT > 您使用字节:00000111 > 十六进制:0x07