Skip to content

Commit

Permalink
Fix sticky_keys hold release (#1055)
Browse files Browse the repository at this point in the history
* Fix sticky_keys hold release
* Update sticky_keys.md
* Update aspell.en.pws
* New unit tests
  • Loading branch information
regicidalplutophage authored Dec 14, 2024
1 parent b4d4f6a commit 973ffd3
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/en/sticky_keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ KC.SK(
### `defer_release`

If `False` (default): release sticky key after the first interrupting key
releases.
is released, or another is pressed. THis PRevents TYpos LIke THese.
If `True`: stay sticky until all keys are released. Useful when combined with
non-sticky modifiers, layer keys, etc...

Expand Down
13 changes: 5 additions & 8 deletions kmk/modules/sticky_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,17 @@ def on_release(self, key, keyboard, *args, **kwargs):
key.state = _SK_RELEASED
# Key in HOLD state is handled like a regular release.
elif key.state == _SK_HOLD:
for sk in self.active_keys.copy():
keyboard.cancel_timeout(sk.timeout)
self.deactivate(keyboard, sk)
keyboard.cancel_timeout(key.timeout)
self.deactivate(keyboard, key)

def on_release_after(self, keyboard, key):
# Key is still pressed but nothing else happend: set to HOLD.
if key.state == _SK_PRESSED:
for sk in self.active_keys:
key.state = _SK_HOLD
keyboard.cancel_timeout(sk.timeout)
key.state = _SK_HOLD
keyboard.cancel_timeout(key.timeout)
# Key got released but nothing else happend: deactivate.
elif key.state == _SK_RELEASED:
for sk in self.active_keys.copy():
self.deactivate(keyboard, sk)
self.deactivate(keyboard, key)

def activate(self, keyboard, key):
if debug.enabled:
Expand Down
76 changes: 74 additions & 2 deletions tests/test_sticky_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,30 @@ def test_sticky_key(self):
[{KC.N0}, {KC.N0, KC.N2}, {KC.N0}, {KC.N0, KC.N3}, {KC.N0}, {}],
)

keyboard.test(
'hold multiple, tap interrupt, release one held, tap interrupt',
[
(0, True),
(1, True),
(2, True),
(2, False),
(1, False),
(3, True),
(3, False),
(0, False),
],
[
{KC.N0},
{KC.N0, KC.N1},
{KC.N0, KC.N1, KC.N2},
{KC.N0, KC.N1},
{KC.N0},
{KC.N0, KC.N3},
{KC.N0},
{},
],
)

def test_sticky_key_stack(self):
self.keyboard.keyboard.active_layers = [0]
keyboard = self.keyboard
Expand Down Expand Up @@ -230,6 +254,30 @@ def test_sticky_key_stack(self):
[{KC.N0}, {KC.N0, KC.N1}, {KC.N0}, {}, {KC.N2}, {}],
)

keyboard.test(
'stack and roll',
[
(0, True),
(0, False),
(1, True),
(1, False),
(2, True),
(3, True),
(2, False),
(3, False),
],
[
{KC.N0},
{KC.N0, KC.N1},
{KC.N0, KC.N1, KC.N2},
{KC.N0, KC.N2},
{KC.N2},
{KC.N2, KC.N3},
{KC.N3},
{},
],
)

def test_sticky_layer(self):
keyboard = self.keyboard
self.keyboard.keyboard.active_layers = [1]
Expand Down Expand Up @@ -397,8 +445,8 @@ def test_sticky_key_deferred(self):
{KC.N0, KC.N1, KC.N2},
{KC.N0, KC.N1, KC.N2, KC.N3},
{KC.N0, KC.N2, KC.N3},
{KC.N2, KC.N3},
{KC.N3},
{KC.N0, KC.N3},
{KC.N0},
{},
],
)
Expand Down Expand Up @@ -455,6 +503,30 @@ def test_sticky_key_deferred(self):
],
)

keyboard.test(
'hold multiple, tap interrupt, release one held, tap interrupt',
[
(0, True),
(1, True),
(2, True),
(2, False),
(1, False),
(3, True),
(3, False),
(0, False),
],
[
{KC.N0},
{KC.N0, KC.N1},
{KC.N0, KC.N1, KC.N2},
{KC.N0, KC.N1},
{KC.N0},
{KC.N0, KC.N3},
{KC.N0},
{},
],
)

def test_sticky_key_in_tapdance(self):
self.keyboard.keyboard.active_layers = [3]
keyboard = self.keyboard
Expand Down
11 changes: 8 additions & 3 deletions util/aspell.en.pws
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
personal_ws-1.1 en 357
personal_ws-1.1 en 363
ADNS
AMS
ANAVI
Expand Down Expand Up @@ -33,7 +33,6 @@ Crkbd
Crowboard
Ctrl
Cygwin
debounce
DFU
DISCOVERABLE
DIY
Expand Down Expand Up @@ -92,6 +91,7 @@ KiCad
Kinesis
Kyria
LEDs
LIke
LSHIFT
Lesovoz
Levinson
Expand Down Expand Up @@ -141,6 +141,7 @@ PCB
PCBA
PCBs
PIO
PRevents
Pico
Pimoroni
PixelBuf
Expand Down Expand Up @@ -181,11 +182,15 @@ ShiftRegisterKeys
Sofle
Spacebar
SparkFun
StickyKeys
Subclasses
Sublicensing
TG
THese
THis
TMK
TRRS
TYpos
TapDance
Teensy
Tindie
Expand Down Expand Up @@ -239,6 +244,7 @@ cryptocurrency
customizable
datasheet
deadzone
debounce
debuggable
detent
dev
Expand Down Expand Up @@ -335,7 +341,6 @@ runtime
scotto
splitkb
stateful
StickyKeys
sublicensable
sublicenses
subrezon
Expand Down

0 comments on commit 973ffd3

Please sign in to comment.