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 <algernon@keyboard.io>
pull/389/head
Gergely Nagy 7 years ago
parent a5ceb5833a
commit dd80ab1abf

@ -154,6 +154,18 @@ properties too:
> >
> Defaults to `true`. > 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 ## Dependencies
* [Kaleidoscope-Ranges](https://github.com/keyboardio/Kaleidoscope-Ranges) * [Kaleidoscope-Ranges](https://github.com/keyboardio/Kaleidoscope-Ranges)

@ -25,6 +25,7 @@ namespace kaleidoscope {
uint32_t OneShot::start_time_ = 0; uint32_t OneShot::start_time_ = 0;
uint16_t OneShot::time_out = 2500; uint16_t OneShot::time_out = 2500;
uint16_t OneShot::hold_time_out = 250; uint16_t OneShot::hold_time_out = 250;
int16_t OneShot::double_tap_time_out = -1;
bool OneShot::double_tap_sticky = true; bool OneShot::double_tap_sticky = true;
OneShot::state_t OneShot::state_; OneShot::state_t OneShot::state_;
OneShot::state_t OneShot::sticky_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)) { if (keyToggledOn(key_state)) {
setPressed(idx); setPressed(idx);
if (isSameAsPrevious(mapped_key) && double_tap_sticky) { if (isSameAsPrevious(mapped_key) && double_tap_sticky) {
if ((millis() - start_time_) <= ((double_tap_time_out == -1) ? time_out : double_tap_time_out)) {
setSticky(idx); setSticky(idx);
saveAsPrevious(mapped_key); saveAsPrevious(mapped_key);
}
} else { } else {
start_time_ = millis(); start_time_ = millis();

@ -43,6 +43,7 @@ class OneShot : public KaleidoscopePlugin {
cancel(false); cancel(false);
} }
static uint16_t time_out; static uint16_t time_out;
static int16_t double_tap_time_out;
static uint16_t hold_time_out; static uint16_t hold_time_out;
static bool double_tap_sticky; static bool double_tap_sticky;

Loading…
Cancel
Save