a62d39a252
* 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
115 lines
2.7 KiB
Python
115 lines
2.7 KiB
Python
from time import sleep
|
|
|
|
|
|
def passthrough(key, keyboard, *args, **kwargs):
|
|
return keyboard
|
|
|
|
|
|
def default_pressed(key, keyboard, KC, coord_int=None, coord_raw=None, *args, **kwargs):
|
|
keyboard.hid_pending = True
|
|
|
|
keyboard.keys_pressed.add(key)
|
|
|
|
return keyboard
|
|
|
|
|
|
def default_released(
|
|
key, keyboard, KC, coord_int=None, coord_raw=None, *args, **kwargs # NOQA
|
|
):
|
|
keyboard.hid_pending = True
|
|
keyboard.keys_pressed.discard(key)
|
|
|
|
return keyboard
|
|
|
|
|
|
def reset(*args, **kwargs):
|
|
import microcontroller
|
|
|
|
microcontroller.reset()
|
|
|
|
|
|
def bootloader(*args, **kwargs):
|
|
import microcontroller
|
|
|
|
microcontroller.on_next_reset(microcontroller.RunMode.BOOTLOADER)
|
|
microcontroller.reset()
|
|
|
|
|
|
def debug_pressed(key, keyboard, KC, *args, **kwargs):
|
|
if keyboard.debug_enabled:
|
|
print('DebugDisable()')
|
|
else:
|
|
print('DebugEnable()')
|
|
|
|
keyboard.debug_enabled = not keyboard.debug_enabled
|
|
|
|
return keyboard
|
|
|
|
|
|
def gesc_pressed(key, keyboard, KC, *args, **kwargs):
|
|
GESC_TRIGGERS = {KC.LSHIFT, KC.RSHIFT, KC.LGUI, KC.RGUI}
|
|
|
|
if GESC_TRIGGERS.intersection(keyboard.keys_pressed):
|
|
# First, release GUI if already pressed
|
|
keyboard._send_hid()
|
|
# if Shift is held, KC_GRAVE will become KC_TILDE on OS level
|
|
keyboard.keys_pressed.add(KC.GRAVE)
|
|
keyboard.hid_pending = True
|
|
return keyboard
|
|
|
|
# else return KC_ESC
|
|
keyboard.keys_pressed.add(KC.ESCAPE)
|
|
keyboard.hid_pending = True
|
|
|
|
return keyboard
|
|
|
|
|
|
def gesc_released(key, keyboard, KC, *args, **kwargs):
|
|
keyboard.keys_pressed.discard(KC.ESCAPE)
|
|
keyboard.keys_pressed.discard(KC.GRAVE)
|
|
keyboard.hid_pending = True
|
|
return keyboard
|
|
|
|
|
|
def bkdl_pressed(key, keyboard, KC, *args, **kwargs):
|
|
BKDL_TRIGGERS = {KC.LGUI, KC.RGUI}
|
|
|
|
if BKDL_TRIGGERS.intersection(keyboard.keys_pressed):
|
|
keyboard._send_hid()
|
|
keyboard.keys_pressed.add(KC.DEL)
|
|
keyboard.hid_pending = True
|
|
return keyboard
|
|
|
|
# else return KC_ESC
|
|
keyboard.keys_pressed.add(KC.BKSP)
|
|
keyboard.hid_pending = True
|
|
|
|
return keyboard
|
|
|
|
|
|
def bkdl_released(key, keyboard, KC, *args, **kwargs):
|
|
keyboard.keys_pressed.discard(KC.BKSP)
|
|
keyboard.keys_pressed.discard(KC.DEL)
|
|
keyboard.hid_pending = True
|
|
return keyboard
|
|
|
|
|
|
def sleep_pressed(key, keyboard, KC, *args, **kwargs):
|
|
sleep(key.meta.ms / 1000)
|
|
return keyboard
|
|
|
|
|
|
def uc_mode_pressed(key, keyboard, *args, **kwargs):
|
|
keyboard.unicode_mode = key.meta.mode
|
|
|
|
return keyboard
|
|
|
|
|
|
def hid_switch(key, keyboard, *args, **kwargs):
|
|
keyboard.hid_type, keyboard.secondary_hid_type = (
|
|
keyboard.secondary_hid_type,
|
|
keyboard.hid_type,
|
|
)
|
|
keyboard._init_hid()
|
|
return keyboard
|