diff options
-rw-r--r-- | quantum/quantum_keycodes.h | 1 | ||||
-rw-r--r-- | tmk_core/common/action_macro.h | 26 |
2 files changed, 25 insertions, 2 deletions
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 4566395fd..e0d469561 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h | |||
@@ -249,6 +249,7 @@ enum quantum_keycodes { | |||
249 | #define MACROTAP(kc) (kc | QK_MACRO | FUNC_TAP<<8) | 249 | #define MACROTAP(kc) (kc | QK_MACRO | FUNC_TAP<<8) |
250 | #define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE) | 250 | #define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE) |
251 | 251 | ||
252 | |||
252 | // L-ayer, T-ap - 256 keycode max, 16 layer max | 253 | // L-ayer, T-ap - 256 keycode max, 16 layer max |
253 | #define LT(layer, kc) (kc | QK_LAYER_TAP | ((layer & 0xF) << 8)) | 254 | #define LT(layer, kc) (kc | QK_LAYER_TAP | ((layer & 0xF) << 8)) |
254 | 255 | ||
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 |