Allow user to customize which key will cancel one-shot keys

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/1024/head
Michael Richters 4 years ago
parent dc21cc2895
commit 6dd77b96c4
No known key found for this signature in database
GPG Key ID: 1288FD13E4EEF0C0

@ -27,7 +27,17 @@ The plugin only makes sense when using one-shot keys.
## Plugin methods ## 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 ## Dependencies

@ -24,20 +24,22 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
Key EscapeOneShot::cancel_oneshot_key_{Key_Escape};
EventHandlerResult EscapeOneShot::onKeyswitchEvent( EventHandlerResult EscapeOneShot::onKeyswitchEvent(
Key &key, KeyAddr key_addr, uint8_t key_state) { Key &key, KeyAddr key_addr, uint8_t key_state) {
// We only act on an escape key that has just been pressed, and not // We only act on an escape key (or `cancel_oneshot_key_`, if that has been
// generated by some other plugin. Also, only if at least one // set) that has just been pressed, and not generated by some other
// OneShot key is active and/or sticky. Last, only if there are no // plugin. Also, only if at least one OneShot key is active and/or
// OneShot keys currently being held. // sticky. Last, only if there are no OneShot keys currently being held.
if (key == Key_Escape && if (key == cancel_oneshot_key_ &&
keyToggledOn(key_state) && keyToggledOn(key_state) &&
!(key_state & INJECTED) && !(key_state & INJECTED) &&
::OneShot.isActive()) { ::OneShot.isActive()) {
// Cancel all OneShot keys // Cancel all OneShot keys
::OneShot.cancel(true); ::OneShot.cancel(true);
// Change the escape key to a blank key, and signal that event processing is // Change the cancellation key to a blank key, and signal that event
// complete. // processing is complete.
key = Key_NoKey; key = Key_NoKey;
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }

@ -19,6 +19,8 @@
#include "kaleidoscope/Runtime.h" #include "kaleidoscope/Runtime.h"
constexpr Key OneShotCancelKey {kaleidoscope::ranges::OS_CANCEL};
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
class EscapeOneShot : public kaleidoscope::Plugin { class EscapeOneShot : public kaleidoscope::Plugin {
@ -26,6 +28,13 @@ class EscapeOneShot : public kaleidoscope::Plugin {
EscapeOneShot(void) {} EscapeOneShot(void) {}
EventHandlerResult onKeyswitchEvent(Key &key, KeyAddr key_addr, uint8_t key_state); 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_;
}; };
} }
} }

@ -56,6 +56,7 @@ enum : uint16_t {
OSL_FIRST, OSL_FIRST,
OSL_LAST = OSL_FIRST + 7, OSL_LAST = OSL_FIRST + 7,
OS_LAST = OSL_LAST, OS_LAST = OSL_LAST,
OS_CANCEL,
DU_FIRST, DU_FIRST,
DUM_FIRST = DU_FIRST, DUM_FIRST = DU_FIRST,
DUM_LAST = DUM_FIRST + (8 << 8), DUM_LAST = DUM_FIRST + (8 << 8),

Loading…
Cancel
Save