diff options
Diffstat (limited to 'tmk_core/common/action_macro.h')
-rw-r--r-- | tmk_core/common/action_macro.h | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/tmk_core/common/action_macro.h b/tmk_core/common/action_macro.h index aedc32ec6..f373f5068 100644 --- a/tmk_core/common/action_macro.h +++ b/tmk_core/common/action_macro.h | |||
@@ -20,11 +20,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
20 | #include "progmem.h" | 20 | #include "progmem.h" |
21 | 21 | ||
22 | 22 | ||
23 | #define MACRO_NONE 0 | 23 | |
24 | typedef uint8_t macro_t; | ||
25 | |||
26 | #define MACRO_NONE (macro_t*)0 | ||
24 | #define MACRO(...) ({ static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; }) | 27 | #define MACRO(...) ({ static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; }) |
25 | #define MACRO_GET(p) pgm_read_byte(p) | 28 | #define MACRO_GET(p) pgm_read_byte(p) |
26 | 29 | ||
27 | typedef uint8_t macro_t; | 30 | // Sends press when the macro key is pressed, release when release, or tap_macro when the key has been tapped |
31 | #define MACRO_TAP_HOLD(record, press, release, tap_macro) ( ((record)->event.pressed) ? \ | ||
32 | ( ((record)->tap.count <= 0 || (record)->tap.interrupted) ? (press) : MACRO_NONE ) : \ | ||
33 | ( ((record)->tap.count > 0 && !((record)->tap.interrupted)) ? (tap_macro) : (release) ) ) | ||
34 | |||
35 | // Holds down the modifier mod when the macro key is held, or sends macro instead when tapped | ||
36 | #define MACRO_TAP_HOLD_MOD(record, macro, mod) MACRO_TAP_HOLD(record, (MACRO(D(mod), END)), MACRO(U(mod), END), macro) | ||
37 | |||
38 | // Holds down the modifier mod when the macro key is held, or pressed a shifted key when tapped (eg: shift+3 for #) | ||
39 | #define MACRO_TAP_SHFT_KEY_HOLD_MOD(record, key, mod) MACRO_TAP_HOLD_MOD(record, (MACRO(I(10), D(LSFT), T(key), U(LSFT), END)), mod) | ||
40 | |||
41 | |||
42 | // Momentary switch layer when held, sends macro if tapped | ||
43 | #define MACRO_TAP_HOLD_LAYER(record, macro, layer) ( ((record)->event.pressed) ? \ | ||
44 | ( ((record)->tap.count <= 0 || (record)->tap.interrupted) ? ({layer_on((layer)); MACRO_NONE; }) : MACRO_NONE ) : \ | ||
45 | ( ((record)->tap.count > 0 && !((record)->tap.interrupted)) ? (macro) : ({layer_off((layer)); MACRO_NONE; }) ) ) | ||
46 | |||
47 | // Momentary switch layer when held, presses a shifted key when tapped (eg: shift+3 for #) | ||
48 | #define MACRO_TAP_SHFT_KEY_HOLD_LAYER(record, key, layer) MACRO_TAP_HOLD_LAYER(record, MACRO(I(10), D(LSFT), T(key), U(LSFT), END), layer) | ||
49 | |||
28 | 50 | ||
29 | 51 | ||
30 | #ifndef NO_ACTION_MACRO | 52 | #ifndef NO_ACTION_MACRO |