From 31c7133e04db35aff7f1375ecea5bad1fe411128 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 1 Dec 2016 09:50:41 +0100 Subject: [PATCH] Macros: A way to run the macro on keypress only Add a `MACRODOWN` convenience macro, that will only run the given macro when the key toggled on. It assumes that it is called from a function with a `keyState` argument. If the key is not pressed, the macro will evaluate to `MACRO_NONE`. Signed-off-by: Gergely Nagy --- libraries/Keyboardio-Macros/src/MacroSteps.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/Keyboardio-Macros/src/MacroSteps.h b/libraries/Keyboardio-Macros/src/MacroSteps.h index 50a09087..f33d0fb3 100644 --- a/libraries/Keyboardio-Macros/src/MacroSteps.h +++ b/libraries/Keyboardio-Macros/src/MacroSteps.h @@ -13,6 +13,7 @@ typedef uint8_t macro_t; #define MACRO_NONE 0 #define MACRO(...) ({static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; }) +#define MACRODOWN(...) (key_toggled_on(keyState) ? MACRO(__VA_ARGS__) : MACRO_NONE) #define I(n) MACRO_ACTION_STEP_INTERVAL, n #define W(n) MACRO_ACTION_STEP_WAIT, n