From 7fbda871c20af19e0cf3597c8dc8dc64885afda0 Mon Sep 17 00:00:00 2001 From: patrickmcquay <60482558+patrickmcquay@users.noreply.github.com> Date: Mon, 31 Jan 2022 22:51:22 -0500 Subject: [PATCH] real fix for swallowing keys, use a buffer and only process one key at a time. --- kmk/kmk_keyboard.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/kmk/kmk_keyboard.py b/kmk/kmk_keyboard.py index 1adf21d..c48e0ce 100644 --- a/kmk/kmk_keyboard.py +++ b/kmk/kmk_keyboard.py @@ -44,6 +44,7 @@ class KMKKeyboard: current_key = None matrix_update = None secondary_matrix_update = None + matrix_update_queue = [] _matrix_modify = None state_changed = False _old_timeouts_len = None @@ -142,7 +143,13 @@ class KMKKeyboard: int_coord = intify_coordinate(row, col) - self.current_key = self._find_key_in_map(int_coord, row, col) + if not is_pressed: + self.current_key = self._coordkeys_pressed[int_coord] + if self.debug_enabled: + print('PressedKeyResolution(key={})'.format(self.current_key)) + + if self.current_key is None: + self.current_key = self._find_key_in_map(int_coord, row, col) if is_pressed: self._coordkeys_pressed[int_coord] = self.current_key @@ -410,10 +417,23 @@ class KMKKeyboard: self.after_matrix_scan() - self._handle_matrix_report(self.secondary_matrix_update) - self.secondary_matrix_update = None - self._handle_matrix_report(self.matrix_update) - self.matrix_update = None + if self.secondary_matrix_update: + # bytearray constructor here to produce a copy + # otherwise things get strange when self.secondary_matrix_update + # gets modified. + self.matrix_update_queue.append(bytearray(self.secondary_matrix_update)) + self.secondary_matrix_update = None + + if self.matrix_update: + # bytearray constructor here to produce a copy + # otherwise things get strange when self.matrix_update + # gets modified. + self.matrix_update_queue.append(bytearray(self.matrix_update)) + self.matrix_update = None + + # only handle one key per cycle. + if self.matrix_update_queue: + self._handle_matrix_report(self.matrix_update_queue.pop(0)) self.before_hid_send()