From f36a18513b9459b8cf778d6009a58a1b9a4a66f3 Mon Sep 17 00:00:00 2001 From: Christian Tu Date: Fri, 17 Sep 2021 15:59:57 +0200 Subject: [PATCH] remember pressed keys and release the same keys when the physical switch is opened, even if the layer has changed between key down and key up and a different key is now active for that matrix position --- kmk/handlers/stock.py | 7 ------- kmk/kmk_keyboard.py | 14 +++++++++++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/kmk/handlers/stock.py b/kmk/handlers/stock.py index 73069b8..f98e4e4 100644 --- a/kmk/handlers/stock.py +++ b/kmk/handlers/stock.py @@ -8,9 +8,6 @@ def passthrough(key, keyboard, *args, **kwargs): def default_pressed(key, keyboard, KC, coord_int=None, coord_raw=None, *args, **kwargs): keyboard.hid_pending = True - if coord_int is not None: - keyboard._coordkeys_pressed[coord_int] = key - keyboard.keys_pressed.add(key) return keyboard @@ -22,10 +19,6 @@ def default_released( keyboard.hid_pending = True keyboard.keys_pressed.discard(key) - if coord_int is not None: - keyboard.keys_pressed.discard(keyboard._coordkeys_pressed.get(coord_int, None)) - keyboard._coordkeys_pressed[coord_int] = None - return keyboard diff --git a/kmk/kmk_keyboard.py b/kmk/kmk_keyboard.py index acb199c..aa556c4 100644 --- a/kmk/kmk_keyboard.py +++ b/kmk/kmk_keyboard.py @@ -148,7 +148,19 @@ class KMKKeyboard: print('MatrixChange(col={} row={} pressed={})'.format(col, row, is_pressed)) int_coord = intify_coordinate(row, col) - kc_changed = self._find_key_in_map(int_coord, row, col) + kc_changed = None + if not is_pressed: + kc_changed = self._coordkeys_pressed[int_coord] + if self.debug_enabled: + print('PressedKeyResolution(key={})'.format(self.state_layer_key)) + + if kc_changed is None: + kc_changed = self._find_key_in_map(int_coord, row, col) + + if is_pressed: + self._coordkeys_pressed[int_coord] = kc_changed + else: + self._coordkeys_pressed[int_coord] = None if kc_changed is None: print('MatrixUndefinedCoordinate(col={} row={})'.format(col, row))