diff --git a/doc/plugin/Cycle.md b/doc/plugin/Cycle.md index cdfe9a9c..ac3e1224 100644 --- a/doc/plugin/Cycle.md +++ b/doc/plugin/Cycle.md @@ -25,9 +25,11 @@ Key_Cycle // later in the Sketch: void cycleAction(Key previous_key, uint8_t cycle_count) { - if (previous_key.raw == Key_A.raw) { - cycleThrough (Key_B, Key_C, Key_D); - } + bool is_shifted = previous_key.flags & SHIFT_HELD; + if (previous_key.keyCode == Key_A.keyCode && is_shifted) + cycleThrough (LSHIFT(Key_A), LSHIFT(Key_B), LSHIFT(Key_C)); + if (previous_key.keyCode == Key_A.keyCode && !is_shifted) + cycleThrough (Key_A, Key_B, Key_C); } KALEIDOSCOPE_INIT_PLUGINS(Cycle); diff --git a/examples/Cycle/Cycle.ino b/examples/Cycle/Cycle.ino index a77830e6..4b28b4f2 100644 --- a/examples/Cycle/Cycle.ino +++ b/examples/Cycle/Cycle.ino @@ -47,9 +47,12 @@ void cycleAction(Key previous_key, uint8_t cycle_count) { Cycle.replace(Key_G); } } - if (previous_key.raw == Key_A.raw) { + + bool is_shifted = previous_key.flags & SHIFT_HELD; + if (previous_key.keyCode == Key_A.keyCode && is_shifted) + cycleThrough(LSHIFT(Key_A), LSHIFT(Key_B), LSHIFT(Key_C), LSHIFT(Key_D)); + if (previous_key.keyCode == Key_A.keyCode && !is_shifted) cycleThrough(Key_A, Key_B, Key_C, Key_D); - } } KALEIDOSCOPE_INIT_PLUGINS(Cycle); diff --git a/src/kaleidoscope/plugin/Cycle.cpp b/src/kaleidoscope/plugin/Cycle.cpp index ec279c7b..00361a83 100644 --- a/src/kaleidoscope/plugin/Cycle.cpp +++ b/src/kaleidoscope/plugin/Cycle.cpp @@ -23,6 +23,7 @@ namespace kaleidoscope { namespace plugin { // --- state --- Key Cycle::last_non_cycle_key_; +uint8_t Cycle::current_modifier_flags_; uint8_t Cycle::cycle_count_; // --- helpers --- @@ -66,9 +67,14 @@ EventHandlerResult Cycle::onKeyswitchEvent(Key &mapped_key, byte row, byte col, if (!isCycle(mapped_key)) { if (keyToggledOn(key_state)) { - last_non_cycle_key_.raw = mapped_key.raw; + current_modifier_flags_ |= toModFlag(mapped_key.keyCode); + last_non_cycle_key_.keyCode = mapped_key.keyCode; + last_non_cycle_key_.flags = current_modifier_flags_; cycle_count_ = 0; } + if (keyToggledOff(key_state)) { + current_modifier_flags_ &= ~toModFlag(mapped_key.keyCode); + } return EventHandlerResult::OK; } @@ -81,6 +87,26 @@ EventHandlerResult Cycle::onKeyswitchEvent(Key &mapped_key, byte row, byte col, return EventHandlerResult::EVENT_CONSUMED; } +uint8_t Cycle::toModFlag(uint8_t keyCode) { + switch (keyCode) { + case Key_LeftShift.keyCode: + case Key_RightShift.keyCode: + return SHIFT_HELD; + case Key_LeftAlt.keyCode: + return LALT_HELD; + case Key_RightAlt.keyCode: + return RALT_HELD; + case Key_LeftControl.keyCode: + case Key_RightControl.keyCode: + return CTRL_HELD; + case Key_LeftGui.keyCode: + case Key_RightGui.keyCode: + return GUI_HELD; + default: + return 0; + } +} + } } diff --git a/src/kaleidoscope/plugin/Cycle.h b/src/kaleidoscope/plugin/Cycle.h index d5004626..b61bf946 100644 --- a/src/kaleidoscope/plugin/Cycle.h +++ b/src/kaleidoscope/plugin/Cycle.h @@ -39,8 +39,10 @@ class Cycle : public kaleidoscope::Plugin { EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state); private: + static uint8_t toModFlag(uint8_t keyCode); static Key last_non_cycle_key_; static uint8_t cycle_count_; + static uint8_t current_modifier_flags_; }; } }