diff --git a/kmk/modules/capsword.py b/kmk/modules/capsword.py index b264986e1..c1b44a030 100644 --- a/kmk/modules/capsword.py +++ b/kmk/modules/capsword.py @@ -31,26 +31,30 @@ def before_matrix_scan(self, keyboard): return def process_key(self, keyboard, key, is_pressed, int_coord): - if self._cw_active and key != KC.CW: - continue_cw = False - # capitalize alphabets - if key.code in self._alphabets: - continue_cw = True - keyboard.process_key(KC.LSFT, is_pressed) - elif ( - not isinstance(key, KeyboardKey) - or isinstance(key, ModifierKey) - or key.code in self._numbers - or key in self.keys_ignored - ): - continue_cw = True - # requests and cancels existing timeouts - if is_pressed: - if continue_cw: - self.discard_timeout(keyboard) - self.request_timeout(keyboard) - else: - self.process_timeout() + if not self._cw_active or key == KC.CW: + return key + + continue_cw = False + + # capitalize alphabets + if isinstance(key, KeyboardKey) and key.code in self._alphabets: + keyboard.process_key(KC.LSFT, is_pressed) + continue_cw = True + elif ( + not isinstance(key, KeyboardKey) + or isinstance(key, ModifierKey) + or key.code in self._numbers + or key in self.keys_ignored + ): + continue_cw = True + + # requests and cancels existing timeouts + if is_pressed: + if continue_cw: + self.discard_timeout(keyboard) + self.request_timeout(keyboard) + else: + self.process_timeout() return key diff --git a/tests/test_capsword.py b/tests/test_capsword.py index 2ab37b91d..3fe155053 100644 --- a/tests/test_capsword.py +++ b/tests/test_capsword.py @@ -12,7 +12,7 @@ def setUp(self): self.kb = KeyboardTest( [CapsWord(timeout=2 * KeyboardTest.loop_delay_ms)], [ - [KC.CW, KC.A, KC.Z, KC.N1, KC.N0, KC.SPC], + [KC.CW, KC.A, KC.Z, KC.N1, KC.N0, KC.SPC, KC.NO], ], debug_enabled=False, ) @@ -60,6 +60,24 @@ def test_capsword(self): ], ) + def test_capsword_w_special_key(self): + self.kb.test( + '', + [ + (0, True), + (0, False), + (1, True), + (1, False), + (6, True), + (6, False), + (1, True), + (1, False), + (0, True), + (0, False), + ], + [{KC.LSFT, KC.A}, {}, {KC.LSFT, KC.A}, {}], + ) + if __name__ == '__main__': unittest.main()