Parse media and system keys.
This commit is contained in:
+32
-5
@@ -4,9 +4,18 @@
|
|||||||
|
|
||||||
#define longCompactLengthPrefix 0xff
|
#define longCompactLengthPrefix 0xff
|
||||||
|
|
||||||
#define HAS_SCANCODE (1 << 0)
|
#define HAS_SCANCODE 0b00001
|
||||||
#define HAS_MODS (1 << 1)
|
#define HAS_MODS 0b00010
|
||||||
#define HAS_LONGPRESS (1 << 2)
|
#define HAS_LONGPRESS 0b00100
|
||||||
|
#define KEYSTROKE_TYPE 0b11000
|
||||||
|
#define KEYSTROKE_TYPE_SHIFT 3
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
KeystrokeType_Basic,
|
||||||
|
KeystrokeType_ShortMedia,
|
||||||
|
KeystrokeType_LongMedia,
|
||||||
|
KeystrokeType_System,
|
||||||
|
} serialized_keystroke_type_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const uint8_t *buffer;
|
const uint8_t *buffer;
|
||||||
@@ -16,7 +25,7 @@ typedef struct {
|
|||||||
enum {
|
enum {
|
||||||
NoneAction = 0,
|
NoneAction = 0,
|
||||||
KeyStrokeAction = 1,
|
KeyStrokeAction = 1,
|
||||||
LastKeyStrokeAction = 7,
|
LastKeyStrokeAction = 31,
|
||||||
SwitchLayerAction,
|
SwitchLayerAction,
|
||||||
SwitchKeymapAction,
|
SwitchKeymapAction,
|
||||||
MouseAction,
|
MouseAction,
|
||||||
@@ -29,6 +38,11 @@ static uint8_t readUInt8(serialized_buffer_t *buffer) {
|
|||||||
return buffer->buffer[buffer->offset++];
|
return buffer->buffer[buffer->offset++];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint16_t readUInt16(serialized_buffer_t *buffer) {
|
||||||
|
uint8_t firstByte = buffer->buffer[buffer->offset++];
|
||||||
|
return firstByte + (buffer->buffer[buffer->offset++] << 8);
|
||||||
|
}
|
||||||
|
|
||||||
static bool readBool(serialized_buffer_t *buffer) {
|
static bool readBool(serialized_buffer_t *buffer) {
|
||||||
return buffer->buffer[buffer->offset++] == 1;
|
return buffer->buffer[buffer->offset++] == 1;
|
||||||
}
|
}
|
||||||
@@ -108,8 +122,21 @@ static void processKeyStrokeAction(key_action_t *action, uint8_t actionType, ser
|
|||||||
|
|
||||||
action->type = KEY_ACTION_KEYSTROKE;
|
action->type = KEY_ACTION_KEYSTROKE;
|
||||||
|
|
||||||
|
uint8_t keystrokeType = (KEYSTROKE_TYPE & flags) >> KEYSTROKE_TYPE_SHIFT;
|
||||||
|
switch (keystrokeType) {
|
||||||
|
case KeystrokeType_Basic:
|
||||||
|
action->keystroke.keystrokeType = KEYSTROKE_BASIC;
|
||||||
|
break;
|
||||||
|
case KeystrokeType_ShortMedia:
|
||||||
|
case KeystrokeType_LongMedia:
|
||||||
|
action->keystroke.keystrokeType = KEYSTROKE_MEDIA;
|
||||||
|
break;
|
||||||
|
case KeystrokeType_System:
|
||||||
|
action->keystroke.keystrokeType = KEYSTROKE_SYSTEM;
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (flags & HAS_SCANCODE) {
|
if (flags & HAS_SCANCODE) {
|
||||||
action->keystroke.scancode = readUInt8(buffer);
|
action->keystroke.scancode = keystrokeType == KeystrokeType_LongMedia ? readUInt16(buffer) : readUInt8(buffer);
|
||||||
}
|
}
|
||||||
if (flags & HAS_MODS) {
|
if (flags & HAS_MODS) {
|
||||||
action->keystroke.modifiers = readUInt8(buffer);
|
action->keystroke.modifiers = readUInt8(buffer);
|
||||||
|
|||||||
Reference in New Issue
Block a user