2022-01-26 21:34:50 +01:00
|
|
|
import kmk.handlers.stock as handlers
|
2020-10-21 21:19:42 +02:00
|
|
|
from kmk.keys import make_argumented_key
|
2022-07-21 17:50:30 +02:00
|
|
|
from kmk.modules.holdtap import HoldTap, HoldTapKeyMeta
|
|
|
|
|
|
|
|
|
|
|
|
def mod_tap_validator(
|
|
|
|
kc, mods=None, prefer_hold=True, tap_interrupted=False, tap_time=None
|
|
|
|
):
|
|
|
|
'''
|
|
|
|
Validates that mod tap keys are correctly used
|
|
|
|
'''
|
|
|
|
return ModTapKeyMeta(
|
|
|
|
kc=kc,
|
|
|
|
mods=mods,
|
|
|
|
prefer_hold=prefer_hold,
|
|
|
|
tap_interrupted=tap_interrupted,
|
|
|
|
tap_time=tap_time,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ModTapKeyMeta(HoldTapKeyMeta):
|
|
|
|
def __init__(self, kc=None, mods=None, **kwargs):
|
|
|
|
super().__init__(tap=kc, hold=mods, **kwargs)
|
2021-09-19 14:14:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ModTap(HoldTap):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
make_argumented_key(
|
|
|
|
validator=mod_tap_validator,
|
|
|
|
names=('MT',),
|
|
|
|
on_press=self.ht_pressed,
|
|
|
|
on_release=self.ht_released,
|
|
|
|
)
|
|
|
|
|
2021-10-15 13:18:33 +02:00
|
|
|
def ht_activate_hold(self, key, keyboard, *args, **kwargs):
|
2022-05-03 19:20:23 +02:00
|
|
|
handlers.default_pressed(key.meta.hold, keyboard, None)
|
2021-09-19 14:14:13 +02:00
|
|
|
|
|
|
|
def ht_deactivate_hold(self, key, keyboard, *args, **kwargs):
|
2022-05-03 19:20:23 +02:00
|
|
|
handlers.default_released(key.meta.hold, keyboard, None)
|
2021-09-19 14:14:13 +02:00
|
|
|
|
|
|
|
def ht_activate_tap(self, key, keyboard, *args, **kwargs):
|
2022-05-03 19:20:23 +02:00
|
|
|
handlers.default_pressed(key.meta.tap, keyboard, None)
|
2021-09-19 14:14:13 +02:00
|
|
|
|
|
|
|
def ht_deactivate_tap(self, key, keyboard, *args, **kwargs):
|
2022-05-03 19:20:23 +02:00
|
|
|
handlers.default_released(key.meta.tap, keyboard, None)
|