diff --git a/plugins/Kaleidoscope-Escape-OneShot/README.md b/plugins/Kaleidoscope-Escape-OneShot/README.md index 9db9ae65..8ce762f0 100644 --- a/plugins/Kaleidoscope-Escape-OneShot/README.md +++ b/plugins/Kaleidoscope-Escape-OneShot/README.md @@ -27,7 +27,17 @@ The plugin only makes sense when using one-shot keys. ## Plugin methods -The plugin provides the `EscapeOneShot` object, which has no public methods. +The plugin provides the `EscapeOneShot` object, which has one public +configuration method: + +### `.setCancelKey(key)` + +> Changes the `Key` value that will trigger deactivation of one-shot +> (including sticky) keys. The default is to use `Key_Escape` (the +> normal `Esc` key), but if you would rather have a dedicated key (so +> that you can use `Key_Escape` in combination with one-shot +> modifiers), there is the special `OneShotCancelKey`, which will not +> have any side effects. ## Dependencies diff --git a/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.cpp b/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.cpp index 26367a94..2f60bf5d 100644 --- a/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.cpp +++ b/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.cpp @@ -24,20 +24,22 @@ namespace kaleidoscope { namespace plugin { +Key EscapeOneShot::cancel_oneshot_key_{Key_Escape}; + EventHandlerResult EscapeOneShot::onKeyswitchEvent( Key &key, KeyAddr key_addr, uint8_t key_state) { - // We only act on an escape key that has just been pressed, and not - // generated by some other plugin. Also, only if at least one - // OneShot key is active and/or sticky. Last, only if there are no - // OneShot keys currently being held. - if (key == Key_Escape && + // We only act on an escape key (or `cancel_oneshot_key_`, if that has been + // set) that has just been pressed, and not generated by some other + // plugin. Also, only if at least one OneShot key is active and/or + // sticky. Last, only if there are no OneShot keys currently being held. + if (key == cancel_oneshot_key_ && keyToggledOn(key_state) && !(key_state & INJECTED) && ::OneShot.isActive()) { // Cancel all OneShot keys ::OneShot.cancel(true); - // Change the escape key to a blank key, and signal that event processing is - // complete. + // Change the cancellation key to a blank key, and signal that event + // processing is complete. key = Key_NoKey; return EventHandlerResult::EVENT_CONSUMED; } diff --git a/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.h b/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.h index bc52a8ad..4e0393cd 100644 --- a/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.h +++ b/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.h @@ -19,6 +19,8 @@ #include "kaleidoscope/Runtime.h" +constexpr Key OneShotCancelKey {kaleidoscope::ranges::OS_CANCEL}; + namespace kaleidoscope { namespace plugin { class EscapeOneShot : public kaleidoscope::Plugin { @@ -26,6 +28,13 @@ class EscapeOneShot : public kaleidoscope::Plugin { EscapeOneShot(void) {} EventHandlerResult onKeyswitchEvent(Key &key, KeyAddr key_addr, uint8_t key_state); + + void setCancelKey(Key cancel_key) { + cancel_oneshot_key_ = cancel_key; + } + + private: + static Key cancel_oneshot_key_; }; } } diff --git a/plugins/Kaleidoscope-Ranges/src/Kaleidoscope-Ranges.h b/plugins/Kaleidoscope-Ranges/src/Kaleidoscope-Ranges.h index 75a87388..cd6ef682 100644 --- a/plugins/Kaleidoscope-Ranges/src/Kaleidoscope-Ranges.h +++ b/plugins/Kaleidoscope-Ranges/src/Kaleidoscope-Ranges.h @@ -56,6 +56,7 @@ enum : uint16_t { OSL_FIRST, OSL_LAST = OSL_FIRST + 7, OS_LAST = OSL_LAST, + OS_CANCEL, DU_FIRST, DUM_FIRST = DU_FIRST, DUM_LAST = DUM_FIRST + (8 << 8),