Skip to content

Commit

Permalink
Fix Capsword handling of special keys (#1009)
Browse files Browse the repository at this point in the history
  • Loading branch information
xs5871 authored Jul 26, 2024
1 parent d6cbb8c commit 533e806
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
44 changes: 24 additions & 20 deletions kmk/modules/capsword.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 19 additions & 1 deletion tests/test_capsword.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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()

0 comments on commit 533e806

Please sign in to comment.