Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement key repeat feature #983

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions kmk/modules/key_repeat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from kmk.keys import KC, make_key
from kmk.modules import Module


class KeyRepeat(Module):
def __init__(self):
make_key(
names=('REP',),
on_press=self.on_press,
on_release=self.on_release,
)
self.repeat_key = KC.NO

def on_press(self, key, keyboard, *args, **kwargs):
self.repeat_key.on_press(keyboard)

def on_release(self, key, keyboard, *args, **kwargs):
self.repeat_key.on_release(keyboard)

def during_bootup(self, keyboard):
return

def before_matrix_scan(self, keyboard):
return

def after_matrix_scan(self, keyboard):
return

def process_key(self, keyboard, key, is_pressed, int_coord):
if not key == KC.REP and is_pressed:
self.repeat_key = key

return key

def before_hid_send(self, keyboard):
return

def after_hid_send(self, keyboard):
return

def on_powersave_enable(self, keyboard):
return

def on_powersave_disable(self, keyboard):
return
75 changes: 75 additions & 0 deletions tests/test_key_repeat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import unittest

from kmk.keys import KC
from kmk.modules.holdtap import HoldTap
from kmk.modules.key_repeat import KeyRepeat
from kmk.modules.layers import Layers
from tests.keyboard_test import KeyboardTest

t_within = 2 * KeyboardTest.loop_delay_ms
t_holdtap = 4 * KeyboardTest.loop_delay_ms
t_after = 6 * KeyboardTest.loop_delay_ms


class TestKeyRepeat(unittest.TestCase):
@classmethod
def setUpClass(cls):
KC.clear()

key_repeat = KeyRepeat()

holdtap = HoldTap()
holdtap.tap_time = t_holdtap

cls.keyboard = KeyboardTest(
[Layers(), holdtap, key_repeat],
[
[
KC.REP,
KC.MO(1),
KC.HT(KC.T, KC.H),
KC.EXLM,
],
[
KC.N0,
KC.N1,
KC.N2,
KC.N3,
],
],
debug_enabled=False,
)

def test_key_repeat(self):
self.keyboard.test(
'repeat key on other layer twice',
[
(1, True),
(2, True),
(2, False),
(1, False),
(0, True),
(0, False),
(0, True),
(0, False),
],
[{KC.N2}, {}, {KC.N2}, {}, {KC.N2}, {}],
)

self.keyboard.test(
'repeat key on holdtap tap',
[(2, True), t_within, (2, False), (0, True), (0, False)],
[{KC.T}, {}, {KC.T}, {}],
)

self.keyboard.test(
'repeat key on holdtap hold',
[(2, True), t_after, (2, False), (0, True), (0, False)],
[{KC.H}, {}, {KC.H}, {}],
)

self.keyboard.test(
'repeat key shifted',
[(3, True), (3, False), (0, True), (0, False)],
[{KC.LSFT, KC.N1}, {}, {KC.LSFT, KC.N1}, {}],
)
Loading