diff --git a/README.md b/README.md index f08cccdf..30941768 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,18 @@ properties too: > > Defaults to `true`. +### `.double_tap_time_out` + +> Set this property to the number of milliseconds within which a second +> uninterrupted tap of the same one-shot key will be treated as a sticky-tap. +> Only takes effect when `.double_tap_sticky` is set. +> +> +> Setting the property to `-1` will make the double-tap timeout use `.time_out` +> for its calculations. +> +> Defaults to -1. + ## Dependencies * [Kaleidoscope-Ranges](https://github.com/keyboardio/Kaleidoscope-Ranges) diff --git a/src/Kaleidoscope/OneShot.cpp b/src/Kaleidoscope/OneShot.cpp index f125242f..1fbfd660 100644 --- a/src/Kaleidoscope/OneShot.cpp +++ b/src/Kaleidoscope/OneShot.cpp @@ -25,6 +25,7 @@ namespace kaleidoscope { uint32_t OneShot::start_time_ = 0; uint16_t OneShot::time_out = 2500; uint16_t OneShot::hold_time_out = 250; +int16_t OneShot::double_tap_time_out = -1; bool OneShot::double_tap_sticky = true; OneShot::state_t OneShot::state_; OneShot::state_t OneShot::sticky_state_; @@ -141,9 +142,11 @@ Key OneShot::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_st if (keyToggledOn(key_state)) { setPressed(idx); if (isSameAsPrevious(mapped_key) && double_tap_sticky) { - setSticky(idx); + if ((millis() - start_time_) <= ((double_tap_time_out == -1) ? time_out : double_tap_time_out)) { + setSticky(idx); - saveAsPrevious(mapped_key); + saveAsPrevious(mapped_key); + } } else { start_time_ = millis(); diff --git a/src/Kaleidoscope/OneShot.h b/src/Kaleidoscope/OneShot.h index 3c98c0a6..1bde5c53 100644 --- a/src/Kaleidoscope/OneShot.h +++ b/src/Kaleidoscope/OneShot.h @@ -43,6 +43,7 @@ class OneShot : public KaleidoscopePlugin { cancel(false); } static uint16_t time_out; + static int16_t double_tap_time_out; static uint16_t hold_time_out; static bool double_tap_sticky;