From a31d686911e4fdf0d3dedd1a456be2121edf93b9 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 3 Aug 2017 11:59:33 +0200 Subject: [PATCH] When interrupting a tap-dance sequence, make sure no extras are sent When interrupting, we send a report, release all keys, and mask the interrupting key to avoid issues like sending too many of the interrupting keys. Later on, we unmask the interrupting key if it has been masked. This fixes #9, but requires the masking patches to be merged first. Signed-off-by: Gergely Nagy --- src/Kaleidoscope/TapDance.cpp | 15 ++++++++++++--- src/Kaleidoscope/TapDance.h | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Kaleidoscope/TapDance.cpp b/src/Kaleidoscope/TapDance.cpp index f084d4ff..894555e4 100644 --- a/src/Kaleidoscope/TapDance.cpp +++ b/src/Kaleidoscope/TapDance.cpp @@ -41,7 +41,7 @@ byte TapDance::last_tap_dance_col_; // --- actions --- -void TapDance::interrupt(void) { +void TapDance::interrupt(byte row, byte col) { uint8_t idx = last_tap_dance_key_.raw - ranges::TD_FIRST; tapDanceAction(idx, last_tap_dance_row_, last_tap_dance_col_, tap_count_[idx], Interrupt); @@ -49,6 +49,10 @@ void TapDance::interrupt(void) { end_time_ = 0; + KeyboardHardware.maskKey(row, col); + kaleidoscope::hid::sendKeyboardReport(); + kaleidoscope::hid::releaseAllKeys(); + if (bitRead(pressed_state_, idx)) return; @@ -133,6 +137,7 @@ Key TapDance::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_s if (!keyIsPressed(key_state) && !keyWasPressed(key_state)) { if (isTapDance(mapped_key)) return Key_NoKey; + return mapped_key; } @@ -141,8 +146,12 @@ Key TapDance::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_s return mapped_key; if (keyToggledOn(key_state)) - interrupt(); + interrupt(row, col); + if (KeyboardHardware.isKeyMasked(row, col)) { + KeyboardHardware.unMaskKey(row, col); + return Key_NoKey; + } return mapped_key; } @@ -171,7 +180,7 @@ Key TapDance::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_s if (!keyToggledOn(key_state)) return Key_NoKey; - interrupt(); + interrupt(row, col); } } diff --git a/src/Kaleidoscope/TapDance.h b/src/Kaleidoscope/TapDance.h index 8546262a..70d76f80 100644 --- a/src/Kaleidoscope/TapDance.h +++ b/src/Kaleidoscope/TapDance.h @@ -61,7 +61,7 @@ class TapDance : public KaleidoscopePlugin { static void loopHook(bool is_post_clear); static Key tap(void); - static void interrupt(void); + static void interrupt(byte row, byte col); static void timeout(void); static Key release(uint8_t tap_dance_index); };