From: Adrian L Lange Date: Fri, 23 Oct 2015 18:38:50 +0000 (+0200) Subject: Add support for storing, restoring and clearing modifiers in macros X-Git-Url: https://git.friedersdorff.com/?a=commitdiff_plain;ds=sidebyside;h=5a196b64448dd0b8fe84e5960b7ed4111383b8eb;p=max%2Ftmk_keyboard.git Add support for storing, restoring and clearing modifiers in macros --- diff --git a/tmk_core/common/action_macro.c b/tmk_core/common/action_macro.c index ffaf125c..34e22e57 100644 --- a/tmk_core/common/action_macro.c +++ b/tmk_core/common/action_macro.c @@ -34,6 +34,8 @@ void action_macro_play(const macro_t *macro_p) macro_t macro = END; uint8_t interval = 0; + uint8_t mod_storage; + if (!macro_p) return; while (true) { switch (MACRO_READ()) { @@ -66,6 +68,17 @@ void action_macro_play(const macro_t *macro_p) interval = MACRO_READ(); dprintf("INTERVAL(%u)\n", interval); break; + case MOD_STORE: + mod_storage = get_mods(); + break; + case MOD_RESTORE: + set_mods(mod_storage); + send_keyboard_report(); + break; + case MOD_CLEAR: + clear_mods(); + send_keyboard_report(); + break; case 0x04 ... 0x73: dprintf("DOWN(%02X)\n", macro); register_code(macro); diff --git a/tmk_core/common/action_macro.h b/tmk_core/common/action_macro.h index aedc32ec..4cf2216d 100644 --- a/tmk_core/common/action_macro.h +++ b/tmk_core/common/action_macro.h @@ -64,6 +64,9 @@ enum macro_command_id{ /* 0x74 - 0x83 */ WAIT = 0x74, INTERVAL, + MOD_STORE, + MOD_RESTORE, + MOD_CLEAR, /* 0x84 - 0xf3 (reserved for keycode up) */ @@ -82,6 +85,9 @@ enum macro_command_id{ #define TYPE(key) DOWN(key), UP(key) #define WAIT(ms) WAIT, (ms) #define INTERVAL(ms) INTERVAL, (ms) +#define STORE() MOD_STORE +#define RESTORE() MOD_RESTORE +#define CLEAR() MOD_CLEAR /* key down */ #define D(key) DOWN(KC_##key) @@ -93,6 +99,12 @@ enum macro_command_id{ #define W(ms) WAIT(ms) /* interval */ #define I(ms) INTERVAL(ms) +/* store modifier(s) */ +#define SM() STORE() +/* restore modifier(s) */ +#define RM() RESTORE() +/* clear modifier(s) */ +#define CM() CLEAR() /* for backward comaptibility */ #define MD(key) DOWN(KC_##key)