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

Fix sticky_keys hold release #1055

Merged
merged 7 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
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.
xs5871 marked this conversation as resolved.
Show resolved Hide resolved
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
xs5871 marked this conversation as resolved.
Show resolved Hide resolved
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
96 changes: 94 additions & 2 deletions tests/test_sticky_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,50 @@ def test_sticky_key(self):
[{KC.N0}, {KC.N0, KC.N2}, {KC.N0}, {KC.N0, KC.N3}, {KC.N0}, {}],
)

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That already exists on line 114: stick, multiple interleaved other.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. Then that illustrates the another is pressed doc change.

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 +274,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 +465,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},
xs5871 marked this conversation as resolved.
Show resolved Hide resolved
{},
],
)
Expand Down Expand Up @@ -455,6 +523,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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xs5871 Feel free to fix the aspell dictionary. I've no idea how it should be created or sorted -- the huge diff is because I saw that it was somewhat alphabetized, but apparently I alphabetized it too much.

It already was sorted alphabetically (A-Za-z, just like ASCII). It automatically sorts and increases the dictionary counter if you run utils/spellcheck.sh.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, OK. I'll run it locally then.

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
Loading