kmk_firmware/kmk/common/internal_keycodes.py

81 lines
2.3 KiB
Python
Raw Normal View History

import logging
2018-09-21 21:57:29 +02:00
from kmk.common.event_defs import KEY_DOWN_EVENT, KEY_UP_EVENT
from kmk.common.keycodes import Keycodes
2018-09-21 21:57:29 +02:00
def process_internal_key_event(state, action, changed_key, logger=None):
if logger is None:
logger = logging.getLogger(__name__)
if changed_key.code == Keycodes.Layers._KC_DF:
return df(state, action, changed_key, logger=logger)
elif changed_key.code == Keycodes.Layers._KC_MO:
return mo(state, action, changed_key, logger=logger)
2018-09-23 07:34:20 +02:00
elif changed_key.code == Keycodes.Layers._KC_TG:
return tg(state, action, changed_key, logger=logger)
elif changed_key.code == Keycodes.Layers._KC_TO:
return to(state, action, changed_key, logger=logger)
else:
return state
def tilde(state, action, changed_key, logger):
2018-09-23 00:29:24 +02:00
# TODO Actually process keycodes
return state
def df(state, action, changed_key, logger):
"""Switches the default layer"""
2018-09-23 07:34:20 +02:00
if action['type'] == KEY_DOWN_EVENT:
state.active_layers[0] = changed_key.layer
return state
def mo(state, action, changed_key, logger):
"""Momentarily activates layer, switches off when you let go"""
if action['type'] == KEY_UP_EVENT:
state.active_layers = [
layer for layer in state.active_layers
if layer != changed_key.layer
]
elif action['type'] == KEY_DOWN_EVENT:
state.active_layers.append(changed_key.layer)
return state
def lm(layer, mod):
"""As MO(layer) but with mod active"""
def lt(layer, kc):
"""Momentarily activates layer if held, sends kc if tapped"""
2018-09-23 07:34:20 +02:00
def tg(state, action, changed_key, logger):
"""Toggles the layer (enables it if not active, and vise versa)"""
if action['type'] == KEY_DOWN_EVENT:
if changed_key.layer in state.active_layers:
state.active_layers = [
layer for layer in state.active_layers
if layer != changed_key.layer
]
else:
state.active_layers.append(changed_key.layer)
return state
2018-09-23 07:34:20 +02:00
def to(state, action, changed_key, logger):
"""Activates layer and deactivates all other layers"""
2018-09-23 07:34:20 +02:00
if action['type'] == KEY_DOWN_EVENT:
state.active_layers = [changed_key.layer]
return state
def tt(layer):
"""Momentarily activates layer if held, toggles it if tapped repeatedly"""