make TapDance a module (#281)

* extract tapdance logic into a module

* clean out old tapdance code

* canonicalize key variable names

* split _process_tap_dance into td_pressed and td_released

* implement consistent argument order

* update documentation

* implement Module.process_key for key interception and modification

* fix tapdance realesing instead of pressing

* fix: default parameters in key handler

* cleanup holdtap

* add error handling to modules process_key

* fix: key released too late

Tapped keys didn't release on a "key released" event, but waited for a
timeout. Resulted in, for example, modifiers applying to keys after the
modifier was released.

* fix lint/formatting

* fix tap_time reference in modtap + minimal documentation

* fix lint
This commit is contained in:
xs5871
2022-01-18 05:21:05 +00:00
committed by GitHub
parent 10f8c74ad9
commit a62d39a252
9 changed files with 169 additions and 133 deletions

View File

@@ -3,11 +3,7 @@ from micropython import const
import kmk.handlers.stock as handlers
from kmk.consts import UnicodeMode
from kmk.key_validators import (
key_seq_sleep_validator,
tap_dance_key_validator,
unicode_mode_key_validator,
)
from kmk.key_validators import key_seq_sleep_validator, unicode_mode_key_validator
from kmk.types import AttrDict, UnicodeModeKeyMeta
DEBUG_OUTPUT = False
@@ -167,13 +163,6 @@ class KeyAttrDict(AttrDict):
names=('UC_MODE',),
on_press=handlers.uc_mode_pressed,
)
elif key in ('TAP_DANCE', 'TD'):
make_argumented_key(
validator=tap_dance_key_validator,
names=('TAP_DANCE', 'TD'),
on_press=handlers.td_pressed,
on_release=handlers.td_released,
)
elif key in ('HID_SWITCH', 'HID'):
make_key(names=('HID_SWITCH', 'HID'), on_press=handlers.hid_switch)
else:
@@ -417,7 +406,7 @@ class Key:
def __repr__(self):
return 'Key(code={}, has_modifiers={})'.format(self.code, self.has_modifiers)
def on_press(self, state, coord_int, coord_raw):
def on_press(self, state, coord_int=None, coord_raw=None):
if hasattr(self, '_pre_press_handlers'):
for fn in self._pre_press_handlers:
if not fn(self, state, KC, coord_int, coord_raw):
@@ -431,7 +420,7 @@ class Key:
return ret
def on_release(self, state, coord_int, coord_raw):
def on_release(self, state, coord_int=None, coord_raw=None):
if hasattr(self, '_pre_release_handlers'):
for fn in self._pre_release_handlers:
if not fn(self, state, KC, coord_int, coord_raw):