From 7dd8527aabdf3afeeb258e566e8cde999c94ee07 Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Sun, 22 May 2022 23:49:50 -0500 Subject: [PATCH 1/2] Fix Macros tap sequence parsing Both Macros and DynamicMacros were only reading one byte for each `Key` object in a tap sequence, so it would first read the flags byte of each key in the sequence and treat it as a keycode byte, using a flags byte of `0`. As soon as an unmodified keyboard key was encountered, this would be recognized as the end of the sequence. This change fixes the bug by reading and using the flags byte of each key in the sequence as intended. Signed-off-by: Michael Richters --- .../src/kaleidoscope/plugin/DynamicMacros.cpp | 2 +- plugins/Kaleidoscope-Macros/src/kaleidoscope/plugin/Macros.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/Kaleidoscope-DynamicMacros/src/kaleidoscope/plugin/DynamicMacros.cpp b/plugins/Kaleidoscope-DynamicMacros/src/kaleidoscope/plugin/DynamicMacros.cpp index 39fa0977..c79d25c9 100644 --- a/plugins/Kaleidoscope-DynamicMacros/src/kaleidoscope/plugin/DynamicMacros.cpp +++ b/plugins/Kaleidoscope-DynamicMacros/src/kaleidoscope/plugin/DynamicMacros.cpp @@ -188,7 +188,7 @@ void DynamicMacros::play(uint8_t macro_id) { case MACRO_ACTION_STEP_TAP_SEQUENCE: { while (true) { - key.setFlags(0); + key.setFlags(Runtime.storage().read(pos++)); key.setKeyCode(Runtime.storage().read(pos++)); if (key == Key_NoKey) break; diff --git a/plugins/Kaleidoscope-Macros/src/kaleidoscope/plugin/Macros.cpp b/plugins/Kaleidoscope-Macros/src/kaleidoscope/plugin/Macros.cpp index c1c655c8..9b33c370 100644 --- a/plugins/Kaleidoscope-Macros/src/kaleidoscope/plugin/Macros.cpp +++ b/plugins/Kaleidoscope-Macros/src/kaleidoscope/plugin/Macros.cpp @@ -154,7 +154,7 @@ void Macros::play(const macro_t *macro_p) { case MACRO_ACTION_STEP_TAP_SEQUENCE: { while (true) { - key.setFlags(0); + key.setFlags(pgm_read_byte(macro_p++)); key.setKeyCode(pgm_read_byte(macro_p++)); if (key == Key_NoKey) break; From 7279c073e069f256b5567980ccc461f37ab320de Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Sun, 22 May 2022 23:57:54 -0500 Subject: [PATCH 2/2] Add held DynamicMacros keys to the Keyboard HID report DynamicMacros was missing a necessary `beforeReportingState()` handler that is responsible for adding keys held by an active macro to the HID report. This handler is identical to the one used by the Macros plugin for the same purpose. Signed-off-by: Michael Richters --- .../src/kaleidoscope/plugin/DynamicMacros.cpp | 11 +++++++++++ .../src/kaleidoscope/plugin/DynamicMacros.h | 1 + 2 files changed, 12 insertions(+) diff --git a/plugins/Kaleidoscope-DynamicMacros/src/kaleidoscope/plugin/DynamicMacros.cpp b/plugins/Kaleidoscope-DynamicMacros/src/kaleidoscope/plugin/DynamicMacros.cpp index c79d25c9..c80fd15a 100644 --- a/plugins/Kaleidoscope-DynamicMacros/src/kaleidoscope/plugin/DynamicMacros.cpp +++ b/plugins/Kaleidoscope-DynamicMacros/src/kaleidoscope/plugin/DynamicMacros.cpp @@ -240,6 +240,17 @@ EventHandlerResult DynamicMacros::onKeyEvent(KeyEvent &event) { return EventHandlerResult::EVENT_CONSUMED; } +EventHandlerResult DynamicMacros::beforeReportingState(const KeyEvent &event) { + // Here we add keycodes to the HID report for keys held in a macro sequence. + // This is necessary because Kaleidoscope doesn't know about the supplemental + // `active_macro_keys_[]` array. + for (Key key : active_macro_keys_) { + if (key != Key_NoKey) + Runtime.addToReport(key); + } + return EventHandlerResult::OK; +} + EventHandlerResult DynamicMacros::onNameQuery() { return ::Focus.sendName(F("DynamicMacros")); } diff --git a/plugins/Kaleidoscope-DynamicMacros/src/kaleidoscope/plugin/DynamicMacros.h b/plugins/Kaleidoscope-DynamicMacros/src/kaleidoscope/plugin/DynamicMacros.h index 93a0a2af..1678187f 100644 --- a/plugins/Kaleidoscope-DynamicMacros/src/kaleidoscope/plugin/DynamicMacros.h +++ b/plugins/Kaleidoscope-DynamicMacros/src/kaleidoscope/plugin/DynamicMacros.h @@ -39,6 +39,7 @@ class DynamicMacros : public kaleidoscope::Plugin { public: EventHandlerResult onNameQuery(); EventHandlerResult onKeyEvent(KeyEvent &event); + EventHandlerResult beforeReportingState(const KeyEvent &event); EventHandlerResult onFocusEvent(const char *command); static void reserve_storage(uint16_t size);