2018-12-29 15:03:31 +01:00
|
|
|
from kmk.keycodes import KC, make_key
|
2018-12-29 13:44:52 +01:00
|
|
|
from kmk.types import KeySequenceMeta
|
|
|
|
|
|
|
|
|
|
|
|
def sequence_press_handler(key, state, KC, *args, **kwargs):
|
|
|
|
old_keys_pressed = state.keys_pressed
|
|
|
|
state.keys_pressed = set()
|
|
|
|
|
|
|
|
for ikey in key.meta.seq:
|
|
|
|
if not getattr(ikey, 'no_press', None):
|
|
|
|
state.process_key(ikey, True)
|
|
|
|
state.config._send_hid()
|
|
|
|
if not getattr(ikey, 'no_release', None):
|
|
|
|
state.process_key(ikey, False)
|
|
|
|
state.config._send_hid()
|
|
|
|
|
|
|
|
state.keys_pressed = old_keys_pressed
|
|
|
|
|
|
|
|
return state
|
|
|
|
|
|
|
|
|
|
|
|
def simple_key_sequence(seq):
|
|
|
|
return make_key(
|
|
|
|
meta=KeySequenceMeta(seq),
|
|
|
|
on_press=sequence_press_handler,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def send_string(message):
|
|
|
|
seq = []
|
|
|
|
|
|
|
|
for char in message:
|
2018-12-29 15:03:31 +01:00
|
|
|
kc = KC[char]
|
2018-12-29 13:44:52 +01:00
|
|
|
|
|
|
|
if char.isupper():
|
|
|
|
kc = KC.LSHIFT(kc)
|
|
|
|
|
|
|
|
seq.append(kc)
|
|
|
|
|
|
|
|
return simple_key_sequence(seq)
|