implement per-key tap_time.

This commit is contained in:
xs5871 2022-01-25 19:52:13 +00:00 committed by Kyle Brown
parent 21c058aaa8
commit f30206c7d5
3 changed files with 11 additions and 5 deletions

View File

@ -22,11 +22,11 @@ def layer_key_validator(layer, kc=None):
return LayerKeyMeta(layer=layer, kc=kc) return LayerKeyMeta(layer=layer, kc=kc)
def mod_tap_validator(kc, mods=None, prefer_hold=True): def mod_tap_validator(kc, mods=None, prefer_hold=True, tap_time=None):
''' '''
Validates that mod tap keys are correctly used Validates that mod tap keys are correctly used
''' '''
return ModTapKeyMeta(kc=kc, mods=mods, prefer_hold=prefer_hold) return ModTapKeyMeta(kc=kc, mods=mods, prefer_hold=prefer_hold, tap_time=tap_time)
def tap_dance_key_validator(*codes): def tap_dance_key_validator(*codes):

View File

@ -61,8 +61,12 @@ class HoldTap(Module):
def ht_pressed(self, key, keyboard, *args, **kwargs): def ht_pressed(self, key, keyboard, *args, **kwargs):
'''Do nothing yet, action resolves when key is released, timer expires or other key is pressed.''' '''Do nothing yet, action resolves when key is released, timer expires or other key is pressed.'''
if key.meta.tap_time is None:
tap_time = self.tap_time
else:
tap_time = key.meta.tap_time
timeout_key = keyboard.set_timeout( timeout_key = keyboard.set_timeout(
self.tap_time, tap_time,
lambda: self.on_tap_time_expired(key, keyboard, *args, **kwargs), lambda: self.on_tap_time_expired(key, keyboard, *args, **kwargs),
) )
self.key_states[key] = HoldTapKeyState(timeout_key, *args, **kwargs) self.key_states[key] = HoldTapKeyState(timeout_key, *args, **kwargs)

View File

@ -12,16 +12,18 @@ class AttrDict(dict):
class LayerKeyMeta: class LayerKeyMeta:
def __init__(self, layer, kc=None): def __init__(self, layer, kc=None, tap_time=None):
self.layer = layer self.layer = layer
self.kc = kc self.kc = kc
self.tap_time = tap_time
class ModTapKeyMeta: class ModTapKeyMeta:
def __init__(self, kc=None, mods=None, prefer_hold=True): def __init__(self, kc=None, mods=None, prefer_hold=True, tap_time=None):
self.prefer_hold = prefer_hold self.prefer_hold = prefer_hold
self.kc = kc self.kc = kc
self.mods = mods self.mods = mods
self.tap_time = tap_time
class KeySequenceMeta: class KeySequenceMeta: