New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Macro: fix and redesign #116
Comments
|
use case #136 |
|
And this use case. Users may want to change modifier state in their macro definition.
|
|
Implemented storing, restoring and clearing modifiers. From a1260b5fbc1813229738d81109af2c8dd68101c1 Mon Sep 17 00:00:00 2001
From: Adrian L Lange <mail@p3lim.net>
Date: Fri, 23 Oct 2015 20:38:50 +0200
Subject: [PATCH] Add support for storing, restoring and clearing modifiers in
macros
---
common/action_macro.c | 13 +++++++++++++
common/action_macro.h | 12 ++++++++++++
2 files changed, 25 insertions(+)
diff --git a/common/action_macro.c b/common/action_macro.c
index ffaf125..34e22e5 100644
--- a/common/action_macro.c
+++ b/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/common/action_macro.h b/common/action_macro.h
index aedc32e..4cf2216 100644
--- a/common/action_macro.h
+++ b/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)
--
2.6.2.windows.1 |
|
With that patch, I'm able to write my macro like this: return (record->event.pressed ? MACRO(T(F20), CM(), SM(), T(SLSH), RM(), T(O), END) : MACRO_NONE);Instead of how you suggested in e852582#commitcomment-13938301 |
|
Ah, nice. It is almost exactly what I had in mind. |
|
So you'd have to store > clear > rest of macro > restore > end? |
|
yep. |
|
I'd be fine with that. Updated my patch in case you want to use it. |
- This required a change to the core, see tmk/tmk_keyboard#116.
|
Applied patch, thank you. 5a196b6 Three commands were added: |
Fix for broken link in readme.
At this moment macro uses
add_weak_modsfor all mdofiers. This is intented to prevent macro from breaking real/physical key state when the modifier in macro is released. Butadd_modsis needed for some macro usage, for example, when you want a macro which behaves as real modifier key.Later I'll change macro action behaviour:
KEY_DOWN: uses
register_codeeven for modifierKEY_UP: uses
register_codeeven for modifierAnd add macro actions:
ADD_WEAK_MOD: uses
weak_add_modsDEL_WEAK_MOD: uses
weak_del_modsADD_MOD:
DEL_MOD:
ADD_KEY:
DEL_KEY:
SEND: uses
send_keyboard_reporttmk_keyboard/common/action_macro.c
Line 44 in a5d4a1f
The text was updated successfully, but these errors were encountered: