previous_key in cycleAction now contains modifier key flags

pull/453/head
kriber 6 years ago committed by Gergely Nagy
parent 9bd897526d
commit 01e057e545

@ -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);

@ -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);

@ -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;
}
}
}
}

@ -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_;
};
}
}

Loading…
Cancel
Save