Merge pull request #453 from keyboardio/cycle/prevkey-modflags

previous_key in cycleAction now contains modifier key flags
pull/454/head
Jesse Vincent 6 years ago committed by GitHub
commit 6fb3f208f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -25,9 +25,11 @@ Key_Cycle
// later in the Sketch: // later in the Sketch:
void cycleAction(Key previous_key, uint8_t cycle_count) { void cycleAction(Key previous_key, uint8_t cycle_count) {
if (previous_key.raw == Key_A.raw) { bool is_shifted = previous_key.flags & SHIFT_HELD;
cycleThrough (Key_B, Key_C, Key_D); 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); KALEIDOSCOPE_INIT_PLUGINS(Cycle);

@ -47,9 +47,12 @@ void cycleAction(Key previous_key, uint8_t cycle_count) {
Cycle.replace(Key_G); 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); cycleThrough(Key_A, Key_B, Key_C, Key_D);
}
} }
KALEIDOSCOPE_INIT_PLUGINS(Cycle); KALEIDOSCOPE_INIT_PLUGINS(Cycle);

@ -23,6 +23,7 @@ namespace kaleidoscope {
namespace plugin { namespace plugin {
// --- state --- // --- state ---
Key Cycle::last_non_cycle_key_; Key Cycle::last_non_cycle_key_;
uint8_t Cycle::current_modifier_flags_;
uint8_t Cycle::cycle_count_; uint8_t Cycle::cycle_count_;
// --- helpers --- // --- helpers ---
@ -66,9 +67,14 @@ EventHandlerResult Cycle::onKeyswitchEvent(Key &mapped_key, byte row, byte col,
if (!isCycle(mapped_key)) { if (!isCycle(mapped_key)) {
if (keyToggledOn(key_state)) { 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; cycle_count_ = 0;
} }
if (keyToggledOff(key_state)) {
current_modifier_flags_ &= ~toModFlag(mapped_key.keyCode);
}
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
@ -81,6 +87,26 @@ EventHandlerResult Cycle::onKeyswitchEvent(Key &mapped_key, byte row, byte col,
return EventHandlerResult::EVENT_CONSUMED; 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;
}
}
} }
} }

@ -39,8 +39,10 @@ class Cycle : public kaleidoscope::Plugin {
EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state); EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state);
private: private:
static uint8_t toModFlag(uint8_t keyCode);
static Key last_non_cycle_key_; static Key last_non_cycle_key_;
static uint8_t cycle_count_; static uint8_t cycle_count_;
static uint8_t current_modifier_flags_;
}; };
} }
} }

Loading…
Cancel
Save