Skip to content

Commit

Permalink
Fix layer tap interrupted
Browse files Browse the repository at this point in the history
  • Loading branch information
xs5871 committed Mar 15, 2023
1 parent 878fe0d commit da999fa
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion kmk/kmk_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def _process_resume_buffer(self):
key = ksf.key

# Handle any unaccounted-for layer shifts by looking up the key resolution again.
if ksf.int_coord in self._coordkeys_pressed.keys():
if ksf.int_coord is not None:
key = self._find_key_in_map(ksf.int_coord)

# Resume the processing of the key event and update the HID report
Expand Down
5 changes: 5 additions & 0 deletions kmk/modules/holdtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def process_key(self, keyboard, key, is_pressed, int_coord):
if state.activated != ActivationType.PRESSED:
continue

# holdtap isn't interruptable, resolves on ht_release or timeout.
if not key.meta.tap_interrupted and not key.meta.prefer_hold:
append_buffer = True
continue

# holdtap is interrupted by another key event.
if (is_pressed and not key.meta.tap_interrupted) or (
not is_pressed and key.meta.tap_interrupted and self.key_buffer
Expand Down
2 changes: 1 addition & 1 deletion kmk/modules/oneshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def process_key(self, keyboard, current_key, is_pressed, int_coord):
elif state.activated == ActivationType.INTERRUPTED:
if is_pressed:
send_buffer = True
self.key_buffer.insert(0, (0, key, False))
self.key_buffer.insert(0, (None, key, False))

if send_buffer:
self.key_buffer.append((int_coord, current_key, is_pressed))
Expand Down
2 changes: 1 addition & 1 deletion kmk/modules/tapdance.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, *keys, tap_time=None):
ht_key = KC.HT(
tap=key,
hold=key,
prefer_hold=False,
prefer_hold=True,
tap_interrupted=False,
tap_time=self.tap_time,
)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_holdtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def setUp(self):
KC.clear()

self.t_within = 2 * KeyboardTest.loop_delay_ms
self.t_after = 5 * KeyboardTest.loop_delay_ms
tap_time = (self.t_after + self.t_within) // 2
self.t_after = 6 * KeyboardTest.loop_delay_ms
tap_time = 5 * KeyboardTest.loop_delay_ms

# overide default timeouts
HoldTap.tap_time = tap_time
Expand Down Expand Up @@ -91,13 +91,13 @@ def test_holdtap(self):

keyboard.test(
'LT within tap time rolling -> tap behavior',
[(1, True), t_within, (3, True), t_after, (1, False), (3, False)],
[(1, True), t_within, (3, True), (1, False), (3, False)],
[{KC.B}, {KC.B, KC.D}, {KC.D}, {}],
)

keyboard.test(
'LT within tap time nested -> tap behavior',
[(1, True), t_within, (3, True), (3, False), t_after, (1, False)],
[(1, True), t_within, (3, True), (3, False), (1, False)],
[{KC.B}, {KC.B, KC.D}, {KC.B}, {}],
)

Expand Down
28 changes: 26 additions & 2 deletions tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ def setUp(self):
self.kb = KeyboardTest(
[Layers()],
[
[KC.N0, KC.LM(1, KC.LCTL)],
[KC.A, KC.B],
[
KC.N0,
KC.LM(1, KC.LCTL),
KC.LT(1, KC.N2, tap_interrupted=True, prefer_hold=True),
KC.LT(1, KC.N3, tap_interrupted=False, prefer_hold=True),
],
[KC.A, KC.B, KC.C, KC.D],
],
debug_enabled=False,
)
Expand All @@ -23,6 +28,25 @@ def test_layermod(self):
[{KC.LCTL}, {KC.LCTL, KC.A}, {KC.A}, {}],
)

def test_layertap(self):
self.kb.test(
'Layertap roll',
[(2, True), (0, True), (2, False), (0, False)],
[{KC.N2}, {KC.N0, KC.N2}, {KC.N0}, {}],
)

self.kb.test(
'Layertap tap interrupted',
[(2, True), (0, True), 200, (0, False), (2, False)],
[{KC.A}, {}],
)

self.kb.test(
'Layertap tap interrupted by holdtap',
[(3, True), (2, True), (2, False), (3, False)],
[{KC.C}, {}],
)


if __name__ == '__main__':
unittest.main()

0 comments on commit da999fa

Please sign in to comment.