kmk_firmware/tests/test_hold_tap.py
Phong Le 2ccad46e26
update modtap to holdtap (#718)
* update modtap to holdtap

* Update links

* Revert "Update links"

This reverts commit 8d0cda7c5a43c84dd18b927cb73672158e4f8abc.

* updated docs links

update links in docs

* Update docs/en/Getting_Started.md

Co-authored-by: xs5871 <60395129+xs5871@users.noreply.github.com>

* Update docs/en/Getting_Started.md

Co-authored-by: xs5871 <60395129+xs5871@users.noreply.github.com>

* rename modtap.md to holdtap.md

* Update Getting_Started.md

* Update main.py

* Update modtap.py

* Update modtap.py and add notice

* Update docs/en/porting_to_kmk.md

Co-authored-by: xs5871 <60395129+xs5871@users.noreply.github.com>

* Update docs/en/handwiring.md

Co-authored-by: xs5871 <60395129+xs5871@users.noreply.github.com>

* Update docs/en/contributing.md

Co-authored-by: xs5871 <60395129+xs5871@users.noreply.github.com>

* Update docs/en/contributing.md

Co-authored-by: xs5871 <60395129+xs5871@users.noreply.github.com>

* Update docs/en/ble_hid.md

Co-authored-by: xs5871 <60395129+xs5871@users.noreply.github.com>

* Update docs/en/Getting_Started.md

Co-authored-by: xs5871 <60395129+xs5871@users.noreply.github.com>

* Update docs/en/Getting_Started.md

Co-authored-by: xs5871 <60395129+xs5871@users.noreply.github.com>

* Update docs/en/kmkpython_vs_circuitpython.md

Co-authored-by: xs5871 <60395129+xs5871@users.noreply.github.com>

* Rename modtap.md to holdtap.md

* fixup

---------

Co-authored-by: xs5871 <60395129+xs5871@users.noreply.github.com>
2023-03-03 09:32:41 +00:00

353 lines
9.6 KiB
Python

import unittest
from kmk.keys import KC
from kmk.modules.holdtap import HoldTap, HoldTapRepeat
from kmk.modules.layers import Layers
from tests.keyboard_test import KeyboardTest
class TestHoldTap(unittest.TestCase):
def setUp(self):
KC.clear()
def test_holdtap(self):
keyboard = KeyboardTest(
[Layers(), HoldTap()],
[
[KC.HT(KC.A, KC.LCTL), KC.LT(1, KC.B), KC.C, KC.D],
[KC.N1, KC.N2, KC.N3, KC.N4],
],
debug_enabled=False,
)
keyboard.test('HT tap behaviour', [(0, True), 100, (0, False)], [{KC.A}, {}])
keyboard.test(
'HT hold behaviour', [(0, True), 350, (0, False)], [{KC.LCTL}, {}]
)
# TODO test multiple mods being held
# HT
keyboard.test(
'HT within tap time sequential -> tap behavior',
[(0, True), 100, (0, False), (3, True), (3, False)],
[{KC.A}, {}, {KC.D}, {}],
)
keyboard.test(
'HT within tap time rolling -> hold behavior',
[(0, True), 100, (3, True), 250, (0, False), (3, False)],
[{KC.LCTL}, {KC.LCTL, KC.D}, {KC.D}, {}],
)
keyboard.test(
'HT within tap time nested -> hold behavior',
[(0, True), 100, (3, True), (3, False), 250, (0, False)],
[{KC.LCTL}, {KC.LCTL, KC.D}, {KC.LCTL}, {}],
)
keyboard.test(
'HT after tap time sequential -> hold behavior',
[(0, True), 350, (0, False), (3, True), (3, False)],
[{KC.LCTL}, {}, {KC.D}, {}],
)
keyboard.test(
'HT after tap time rolling -> hold behavior',
[(0, True), 350, (3, True), (0, False), (3, False)],
[{KC.LCTL}, {KC.LCTL, KC.D}, {KC.D}, {}],
)
keyboard.test(
'HT after tap time nested -> hold behavior',
[(0, True), 350, (3, True), (3, False), (0, False)],
[{KC.LCTL}, {KC.LCTL, KC.D}, {KC.LCTL}, {}],
)
# LT
keyboard.test(
'LT within tap time sequential -> tap behavior',
[(1, True), 100, (1, False), (3, True), (3, False)],
[{KC.B}, {}, {KC.D}, {}],
)
keyboard.test(
'LT within tap time rolling -> tap behavior',
[(1, True), 100, (3, True), 250, (1, False), (3, False)],
[{KC.B}, {KC.B, KC.D}, {KC.D}, {}],
)
keyboard.test(
'LT within tap time nested -> tap behavior',
[(1, True), 100, (3, True), (3, False), 250, (1, False)],
[{KC.B}, {KC.B, KC.D}, {KC.B}, {}],
)
keyboard.test(
'LT after tap time sequential -> hold behavior',
[(1, True), 350, (1, False), (3, True), (3, False)],
[{KC.D}, {}],
)
keyboard.test(
'LT after tap time rolling -> hold behavior',
[(1, True), 350, (3, True), (1, False), (3, False)],
[{KC.N4}, {}],
)
keyboard.test(
'LT after tap time nested -> hold behavior',
[(1, True), 350, (3, True), (3, False), (1, False)],
[{KC.N4}, {}],
)
keyboard.test(
'LT after tap time nested -> hold behavior',
[
(0, True),
350,
(1, True),
350,
(3, True),
(3, False),
(1, False),
(0, False),
],
[{KC.LCTL}, {KC.LCTL, KC.N4}, {KC.LCTL}, {}],
)
def test_holdtap_chain(self):
keyboard = KeyboardTest(
[HoldTap()],
[
[
KC.N0,
KC.HT(KC.N1, KC.LCTL, tap_time=50),
KC.HT(KC.N2, KC.LSFT, tap_interrupted=True, tap_time=50),
KC.HT(
KC.N3,
KC.LALT,
prefer_hold=False,
tap_interrupted=True,
tap_time=50,
),
],
],
debug_enabled=False,
)
# t_within = 40
t_after = 60
keyboard.test(
'chained 0',
[(1, True), (2, True), (0, True), (0, False), (2, False), (1, False)],
[
{KC.LCTL},
{KC.LCTL, KC.LSFT},
{KC.LCTL, KC.LSFT, KC.N0},
{KC.LCTL, KC.LSFT},
{KC.LCTL},
{},
],
)
keyboard.test(
'chained 1',
[(2, True), (1, True), (0, True), (0, False), (1, False), (2, False)],
[
{KC.LCTL},
{KC.LCTL, KC.LSFT},
{KC.LCTL, KC.LSFT, KC.N0},
{KC.LCTL, KC.LSFT},
{KC.LSFT},
{},
],
)
keyboard.test(
'chained 2',
[(1, True), (2, True), (0, True), (1, False), (2, False), (0, False)],
[
{KC.LCTL},
{KC.LCTL, KC.LSFT},
{KC.LCTL, KC.LSFT, KC.N0},
{KC.LSFT, KC.N0},
{KC.N0},
{},
],
)
keyboard.test(
'chained 3',
[(1, True), (3, True), (0, True), (0, False), (1, False), (3, False)],
[
{KC.LCTL},
{KC.LCTL, KC.N3},
{KC.LCTL, KC.N3, KC.N0},
{KC.LCTL, KC.N3},
{KC.N3},
{},
],
)
keyboard.test(
'chained 4',
[(1, True), (3, True), (0, True), (3, False), (1, False), (0, False)],
[
{KC.LCTL},
{KC.LCTL, KC.N3},
{KC.LCTL, KC.N0, KC.N3},
{KC.LCTL, KC.N0},
{KC.N0},
{},
],
)
keyboard.test(
'chained 5',
[(3, True), (1, True), (0, True), (0, False), (1, False), (3, False)],
[
{KC.LCTL},
{KC.LCTL, KC.N3},
{KC.LCTL, KC.N3, KC.N0},
{KC.LCTL, KC.N3},
{KC.N3},
{},
],
)
keyboard.test(
'chained 6',
[
(3, True),
(1, True),
t_after,
(0, True),
(0, False),
(1, False),
(3, False),
],
[
{KC.LALT},
{KC.LCTL, KC.LALT},
{KC.LCTL, KC.LALT, KC.N0},
{KC.LCTL, KC.LALT},
{KC.LALT},
{},
],
)
keyboard.test(
'chained 7',
[
(1, True),
(3, True),
t_after,
(0, True),
(0, False),
(1, False),
(3, False),
],
[
{KC.LCTL},
{KC.LCTL, KC.LALT},
{KC.LCTL, KC.LALT, KC.N0},
{KC.LCTL, KC.LALT},
{KC.LALT},
{},
],
)
keyboard.test(
'chained 8',
[(2, True), (3, True), (0, True), (0, False), (2, False), (3, False)],
[
{KC.LSFT},
{KC.LSFT, KC.N3},
{KC.LSFT, KC.N3, KC.N0},
{KC.LSFT, KC.N3},
{KC.N3},
{},
],
)
# TODO test TT
def test_holdtap_repeat(self):
keyboard = KeyboardTest(
[HoldTap()],
[
[
KC.HT(KC.A, KC.B, repeat=HoldTapRepeat.ALL, tap_time=50),
KC.HT(KC.A, KC.B, repeat=HoldTapRepeat.TAP, tap_time=50),
KC.HT(KC.A, KC.B, repeat=HoldTapRepeat.HOLD, tap_time=50),
]
],
debug_enabled=False,
)
t_within = 40
t_after = 60
keyboard.test(
'repeat tap',
[
(0, True),
(0, False),
t_within,
(0, True),
t_after,
(0, False),
(0, True),
(0, False),
t_after,
],
[{KC.A}, {}, {KC.A}, {}, {KC.A}, {}],
)
keyboard.test(
'repeat hold',
[
(0, True),
t_after,
(0, False),
t_within,
(0, True),
(0, False),
(0, True),
(0, False),
t_after,
],
[{KC.B}, {}, {KC.B}, {}, {KC.B}, {}],
)
keyboard.test(
'no repeat after tap_time',
[
(0, True),
(0, False),
t_after,
(0, True),
t_after,
(0, False),
t_after,
(0, True),
(0, False),
t_after,
],
[{KC.A}, {}, {KC.B}, {}, {KC.A}, {}],
)
keyboard.test(
'tap repeat / no hold repeat ',
[(1, True), t_after, (1, False), (1, True), (1, False)],
[{KC.B}, {}, {KC.A}, {}],
)
keyboard.test(
'hold repeat / no tap repeat ',
[(2, True), (2, False), (2, True), t_after, (2, False)],
[{KC.A}, {}, {KC.B}, {}],
)