From 55b035be86f835222a7ecf69b6bb270474d5af9f Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Mon, 27 Mar 2017 10:40:27 +0200 Subject: [PATCH] Introduce a way to describe a tap step Instead of having to use a keydown & keyup step each time we tap a key, use a combined event that does both. While this adds a tiny bit of code to `Macros.play`, if our macros have many key taps (which by and large the most common thing), we save a lot more. Three bytes per tap! Signed-off-by: Gergely Nagy --- src/Kaleidoscope-Macros.cpp | 8 ++++++++ src/MacroSteps.h | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Kaleidoscope-Macros.cpp b/src/Kaleidoscope-Macros.cpp index d9a271b2..128faf5c 100644 --- a/src/Kaleidoscope-Macros.cpp +++ b/src/Kaleidoscope-Macros.cpp @@ -37,6 +37,14 @@ void Macros_::play(const macro_t *macro_p) { handle_key_event(key, 255, 255, WAS_PRESSED | INJECTED); Keyboard.sendReport(); break; + case MACRO_ACTION_STEP_TAP: + key.flags = pgm_read_byte(macro_p++); + key.keyCode = pgm_read_byte(macro_p++); + handle_key_event(key, 255, 255, IS_PRESSED | INJECTED); + Keyboard.sendReport(); + handle_key_event(key, 255, 255, WAS_PRESSED | INJECTED); + Keyboard.sendReport(); + break; case END: default: return; diff --git a/src/MacroSteps.h b/src/MacroSteps.h index 2bef68cb..9a0fd379 100644 --- a/src/MacroSteps.h +++ b/src/MacroSteps.h @@ -7,6 +7,7 @@ typedef enum { MACRO_ACTION_STEP_WAIT, MACRO_ACTION_STEP_KEYDOWN, MACRO_ACTION_STEP_KEYUP, + MACRO_ACTION_STEP_TAP } MacroActionStepType; typedef uint8_t macro_t; @@ -21,6 +22,6 @@ typedef uint8_t macro_t; #define D(k) Dr(Key_ ## k) #define Ur(k) MACRO_ACTION_STEP_KEYUP, (k).flags, (k).keyCode #define U(k) Ur(Key_ ## k) -#define Tr(k) Dr(k), Ur(k) -#define T(k) D(k), U(k) +#define Tr(k) MACRO_ACTION_STEP_TAP, (k).flags, (k).keyCode +#define T(k) Tr(Key_ ## k) #define END MACRO_ACTION_END