From dd80ab1abfa41891a711eef8d14b20f0e0328e80 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 28 Apr 2018 07:05:47 +0200 Subject: [PATCH] Introduce a way to set the double-tap timeout separately Sometimes one wants a longer timeout, also wants the sticky behaviour on double-tap, but would like to use a shorter timeout for the sticky behaviour. The new `double_tap_timeout` property accomplishes just this. Defaults to using `time_out`, for backwards compatibility. Fixes #30. Signed-off-by: Gergely Nagy --- README.md | 12 ++++++++++++ src/Kaleidoscope/OneShot.cpp | 7 +++++-- src/Kaleidoscope/OneShot.h | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) 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;