From ba06d3c8a5f459cb97891f255644498ad70865a9 Mon Sep 17 00:00:00 2001 From: xs5871 Date: Wed, 15 Mar 2023 20:59:03 +0000 Subject: [PATCH] Fix some old holdtap inconsistencies --- kmk/kmk_keyboard.py | 3 ++- kmk/modules/holdtap.py | 16 +++++++--------- tests/test_holdtap.py | 4 ++-- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/kmk/kmk_keyboard.py b/kmk/kmk_keyboard.py index 5b5224e..665aa54 100644 --- a/kmk/kmk_keyboard.py +++ b/kmk/kmk_keyboard.py @@ -268,8 +268,9 @@ class KMKKeyboard: key: Key, is_pressed: bool, int_coord: Optional[int] = None, + reprocess: Optional[bool] = False, ) -> None: - index = self.modules.index(module) + 1 + index = self.modules.index(module) + (0 if reprocess else 1) ksf = KeyBufferFrame( key=key, is_pressed=is_pressed, int_coord=int_coord, index=index ) diff --git a/kmk/modules/holdtap.py b/kmk/modules/holdtap.py index 4f47b39..29a3e12 100644 --- a/kmk/modules/holdtap.py +++ b/kmk/modules/holdtap.py @@ -98,15 +98,12 @@ class HoldTap(Module): self.ht_activate_on_interrupt( key, keyboard, *state.args, **state.kwargs ) + append_buffer = True send_buffer = True # if interrupt on release: store interrupting keys until one of them # is released. - if ( - key.meta.tap_interrupted - and is_pressed - and not isinstance(current_key.meta, HoldTapKeyMeta) - ): + if key.meta.tap_interrupted and is_pressed: append_buffer = True # apply changes with 'side-effects' on key_states or the loop behaviour @@ -115,10 +112,8 @@ class HoldTap(Module): self.key_buffer.append((int_coord, current_key, is_pressed)) current_key = None - elif send_buffer: + if send_buffer: self.send_key_buffer(keyboard) - keyboard.resume_process_key(self, current_key, is_pressed, int_coord) - current_key = None return current_key @@ -226,8 +221,11 @@ class HoldTap(Module): if not self.key_buffer: return + reprocess = False for (int_coord, key, is_pressed) in self.key_buffer: - keyboard.resume_process_key(self, key, is_pressed, int_coord) + keyboard.resume_process_key(self, key, is_pressed, int_coord, reprocess) + if isinstance(key.meta, HoldTapKeyMeta): + reprocess = True self.key_buffer.clear() diff --git a/tests/test_holdtap.py b/tests/test_holdtap.py index b7e56fc..3c9dd5c 100644 --- a/tests/test_holdtap.py +++ b/tests/test_holdtap.py @@ -172,7 +172,7 @@ class TestHoldTap(unittest.TestCase): 'chained 1', [(2, True), (1, True), (0, True), (0, False), (1, False), (2, False)], [ - {KC.LCTL}, + {KC.LSFT}, {KC.LCTL, KC.LSFT}, {KC.LCTL, KC.LSFT, KC.N0}, {KC.LCTL, KC.LSFT}, @@ -224,7 +224,7 @@ class TestHoldTap(unittest.TestCase): 'chained 5', [(3, True), (1, True), (0, True), (0, False), (1, False), (3, False)], [ - {KC.LCTL}, + {KC.N3}, {KC.LCTL, KC.N3}, {KC.LCTL, KC.N3, KC.N0}, {KC.LCTL, KC.N3},