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
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

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

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

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

Loading…
Cancel
Save