Restore Unicode Macro support
This commit is contained in:
parent
57239e3163
commit
8a21b4135d
@ -46,6 +46,7 @@ import supervisor
|
||||
from kmk.consts import LeaderMode, UnicodeMode
|
||||
from kmk.hid import USB_HID
|
||||
from kmk.internal_state import InternalState
|
||||
from kmk.keycodes import KC
|
||||
from kmk.matrix import MatrixScanner
|
||||
|
||||
|
||||
@ -175,6 +176,14 @@ class Firmware:
|
||||
|
||||
self._hid_helper_inst = self.hid_helper()
|
||||
|
||||
# Compile string leader sequences
|
||||
for k, v in self.leader_dictionary.items():
|
||||
if not isinstance(k, tuple):
|
||||
new_key = tuple(KC[c] for c in k)
|
||||
self.leader_dictionary[new_key] = v
|
||||
|
||||
del self.leader_dictionary[k]
|
||||
|
||||
if self.debug_enabled:
|
||||
print("Firin' lazers. Keyboard is booted.")
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
from kmk.keycodes import KC, make_key
|
||||
from kmk.handlers.stock import passthrough
|
||||
from kmk.types import KeySequenceMeta
|
||||
|
||||
|
||||
@ -24,7 +23,6 @@ def simple_key_sequence(seq):
|
||||
return make_key(
|
||||
meta=KeySequenceMeta(seq),
|
||||
on_press=sequence_press_handler,
|
||||
on_release=passthrough,
|
||||
)
|
||||
|
||||
|
||||
|
@ -18,18 +18,6 @@ KEYCODE_CONSUMER = 2
|
||||
KC = AttrDict()
|
||||
|
||||
|
||||
def generate_leader_dictionary_seq(string):
|
||||
# FIXME move to kmk.macros.unicode or somewhere else more fitting
|
||||
# left here for backwards compat with various keymaps that
|
||||
# import this
|
||||
#
|
||||
# I have absolutely no idea why it was in this file to begin with,
|
||||
# probably something related to import order at one point.
|
||||
from kmk.macros.unicode import generate_codepoint_keysym_seq
|
||||
|
||||
return tuple(generate_codepoint_keysym_seq(string, 1))
|
||||
|
||||
|
||||
class Keycode:
|
||||
def __init__(
|
||||
self,
|
||||
@ -530,7 +518,6 @@ make_argumented_key(
|
||||
validator=layer_key_validator,
|
||||
names=('DF',),
|
||||
on_press=layers.df_pressed,
|
||||
on_release=handlers.passthrough,
|
||||
)
|
||||
make_argumented_key(
|
||||
validator=layer_key_validator,
|
||||
@ -548,13 +535,11 @@ make_argumented_key(
|
||||
validator=layer_key_validator,
|
||||
names=('TG',),
|
||||
on_press=layers.tg_pressed,
|
||||
on_release=handlers.passthrough,
|
||||
)
|
||||
make_argumented_key(
|
||||
validator=layer_key_validator,
|
||||
names=('TO',),
|
||||
on_press=layers.to_pressed,
|
||||
on_release=handlers.passthrough,
|
||||
)
|
||||
make_argumented_key(
|
||||
validator=layer_key_validator,
|
||||
|
@ -1,15 +1,15 @@
|
||||
from kmk.consts import UnicodeMode
|
||||
from kmk.keycodes import KC, Macro
|
||||
from kmk.macros.simple import simple_key_sequence
|
||||
from kmk.handlers.sequences import simple_key_sequence
|
||||
from kmk.keycodes import KC, make_key
|
||||
from kmk.types import AttrDict
|
||||
from kmk.util import get_wide_ordinal
|
||||
|
||||
IBUS_KEY_COMBO = KC.LCTRL(KC.LSHIFT(KC.U))
|
||||
RALT_KEY = KC.RALT
|
||||
U_KEY = KC.U
|
||||
ENTER_KEY = KC.ENTER
|
||||
RALT_DOWN_NO_RELEASE = KC.RALT(no_release=True)
|
||||
RALT_UP_NO_PRESS = KC.RALT(no_press=True)
|
||||
IBUS_KEY_COMBO = simple_key_sequence((KC.LCTRL(KC.LSHIFT(KC.U)),))
|
||||
RALT_KEY = simple_key_sequence((KC.RALT,))
|
||||
U_KEY = simple_key_sequence((KC.U,))
|
||||
ENTER_KEY = simple_key_sequence((KC.ENTER,))
|
||||
RALT_DOWN_NO_RELEASE = simple_key_sequence((KC.RALT(no_release=True),))
|
||||
RALT_UP_NO_PRESS = simple_key_sequence((KC.RALT(no_press=True),))
|
||||
|
||||
|
||||
def compile_unicode_string_sequences(string_table):
|
||||
@ -50,6 +50,10 @@ def generate_codepoint_keysym_seq(codepoint, expected_length=4):
|
||||
return seq
|
||||
|
||||
|
||||
def generate_leader_dictionary_seq(string):
|
||||
return tuple(generate_codepoint_keysym_seq(string, 1))
|
||||
|
||||
|
||||
def unicode_codepoint_sequence(codepoints):
|
||||
kc_seqs = (
|
||||
generate_codepoint_keysym_seq(codepoint)
|
||||
@ -61,28 +65,37 @@ def unicode_codepoint_sequence(codepoints):
|
||||
for kc_seq in kc_seqs
|
||||
]
|
||||
|
||||
def _unicode_sequence(state):
|
||||
if state.unicode_mode == UnicodeMode.IBUS:
|
||||
yield from _ibus_unicode_sequence(kc_macros, state)
|
||||
elif state.unicode_mode == UnicodeMode.RALT:
|
||||
yield from _ralt_unicode_sequence(kc_macros, state)
|
||||
elif state.unicode_mode == UnicodeMode.WINC:
|
||||
yield from _winc_unicode_sequence(kc_macros, state)
|
||||
def _unicode_sequence(key, state, *args, **kwargs):
|
||||
if state.config.unicode_mode == UnicodeMode.IBUS:
|
||||
state.process_key(
|
||||
simple_key_sequence(_ibus_unicode_sequence(kc_macros, state)),
|
||||
True,
|
||||
)
|
||||
elif state.config.unicode_mode == UnicodeMode.RALT:
|
||||
state.process_key(
|
||||
simple_key_sequence(_ralt_unicode_sequence(kc_macros, state)),
|
||||
True,
|
||||
)
|
||||
elif state.config.unicode_mode == UnicodeMode.WINC:
|
||||
state.process_key(
|
||||
simple_key_sequence(_winc_unicode_sequence(kc_macros, state)),
|
||||
True,
|
||||
)
|
||||
|
||||
return Macro(keydown=_unicode_sequence)
|
||||
return make_key(on_press=_unicode_sequence)
|
||||
|
||||
|
||||
def _ralt_unicode_sequence(kc_macros, state):
|
||||
for kc_macro in kc_macros:
|
||||
yield RALT_DOWN_NO_RELEASE
|
||||
yield from kc_macro.keydown(state)
|
||||
yield kc_macro
|
||||
yield RALT_UP_NO_PRESS
|
||||
|
||||
|
||||
def _ibus_unicode_sequence(kc_macros, state):
|
||||
for kc_macro in kc_macros:
|
||||
yield IBUS_KEY_COMBO
|
||||
yield from kc_macro.keydown(state)
|
||||
yield kc_macro
|
||||
yield ENTER_KEY
|
||||
|
||||
|
||||
@ -96,4 +109,4 @@ def _winc_unicode_sequence(kc_macros, state):
|
||||
for kc_macro in kc_macros:
|
||||
yield RALT_KEY
|
||||
yield U_KEY
|
||||
yield from kc_macro.keydown(state)
|
||||
yield kc_macro
|
||||
|
@ -1,10 +1,8 @@
|
||||
from kmk.boards.klarank import Firmware
|
||||
from kmk.consts import LeaderMode, UnicodeMode
|
||||
from kmk.handlers.sequences import send_string
|
||||
from kmk.keycodes import KC
|
||||
|
||||
# from kmk.keycodes import generate_leader_dictionary_seq as glds
|
||||
# from kmk.macros.simple import send_string
|
||||
# from kmk.macros.unicode import compile_unicode_string_sequences as cuss
|
||||
from kmk.macros.unicode import compile_unicode_string_sequences as cuss
|
||||
|
||||
keyboard = Firmware()
|
||||
|
||||
@ -12,55 +10,57 @@ keyboard.debug_enabled = True
|
||||
keyboard.unicode_mode = UnicodeMode.LINUX
|
||||
keyboard.tap_time = 750
|
||||
|
||||
# emoticons = cuss({
|
||||
# # Emojis
|
||||
# 'BEER': r'🍺',
|
||||
# 'BEER_TOAST': r'🍻',
|
||||
# 'FACE_CUTE_SMILE': r'😊',
|
||||
# 'FACE_HEART_EYES': r'😍',
|
||||
# 'FACE_JOY': r'😂',
|
||||
# 'FACE_SWEAT_SMILE': r'😅',
|
||||
# 'FACE_THINKING': r'🤔',
|
||||
# 'FIRE': r'🔥',
|
||||
# 'FLAG_CA': r'🇨🇦',
|
||||
# 'FLAG_US': r'🇺🇸',
|
||||
# 'HAND_CLAP': r'👏',
|
||||
# 'HAND_HORNS': r'🤘',
|
||||
# 'HAND_OK': r'👌',
|
||||
# 'HAND_THUMB_DOWN': r'👎',
|
||||
# 'HAND_THUMB_UP': r'👍',
|
||||
# 'HAND_WAVE': r'👋',
|
||||
# 'HEART': r'❤️',
|
||||
# 'MAPLE_LEAF': r'🍁',
|
||||
# 'POOP': r'💩',
|
||||
# 'TADA': r'🎉',
|
||||
#
|
||||
# # Emoticons, but fancier
|
||||
# 'ANGRY_TABLE_FLIP': r'(ノಠ痊ಠ)ノ彡┻━┻',
|
||||
# 'CELEBRATORY_GLITTER': r'+。:.゚ヽ(´∀。)ノ゚.:。+゚゚+。:.゚ヽ(*´∀)ノ゚.:。+゚',
|
||||
# 'SHRUGGIE': r'¯\_(ツ)_/¯',
|
||||
# 'TABLE_FLIP': r'(╯°□°)╯︵ ┻━┻',
|
||||
# })
|
||||
emoticons = cuss({
|
||||
# Emojis
|
||||
'BEER': r'🍺',
|
||||
'BEER_TOAST': r'🍻',
|
||||
'FACE_CUTE_SMILE': r'😊',
|
||||
'FACE_HEART_EYES': r'😍',
|
||||
'FACE_JOY': r'😂',
|
||||
'FACE_SWEAT_SMILE': r'😅',
|
||||
'FACE_THINKING': r'🤔',
|
||||
'FIRE': r'🔥',
|
||||
'FLAG_CA': r'🇨🇦',
|
||||
'FLAG_US': r'🇺🇸',
|
||||
'HAND_CLAP': r'👏',
|
||||
'HAND_HORNS': r'🤘',
|
||||
'HAND_OK': r'👌',
|
||||
'HAND_THUMB_DOWN': r'👎',
|
||||
'HAND_THUMB_UP': r'👍',
|
||||
'HAND_WAVE': r'👋',
|
||||
'HEART': r'❤️',
|
||||
'MAPLE_LEAF': r'🍁',
|
||||
'POOP': r'💩',
|
||||
'TADA': r'🎉',
|
||||
|
||||
# WPM = send_string("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Bibendum arcu vitae elementum curabitur vitae nunc sed. Facilisis sed odio morbi quis.")
|
||||
#
|
||||
# keyboard.leader_mode = LeaderMode.TIMEOUT
|
||||
# keyboard.leader_dictionary = {
|
||||
# glds('hello'): send_string('hello world from kmk macros'),
|
||||
# glds('wpm'): WPM,
|
||||
# glds('atf'): emoticons.ANGRY_TABLE_FLIP,
|
||||
# glds('tf'): emoticons.TABLE_FLIP,
|
||||
# glds('fca'): emoticons.FLAG_CA,
|
||||
# glds('fus'): emoticons.FLAG_US,
|
||||
# glds('cel'): emoticons.CELEBRATORY_GLITTER,
|
||||
# }
|
||||
# Emoticons, but fancier
|
||||
'ANGRY_TABLE_FLIP': r'(ノಠ痊ಠ)ノ彡┻━┻',
|
||||
'CELEBRATORY_GLITTER': r'+。:.゚ヽ(´∀。)ノ゚.:。+゚゚+。:.゚ヽ(*´∀)ノ゚.:。+゚',
|
||||
'SHRUGGIE': r'¯\_(ツ)_/¯',
|
||||
'TABLE_FLIP': r'(╯°□°)╯︵ ┻━┻',
|
||||
})
|
||||
|
||||
WPM = send_string("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Bibendum arcu vitae elementum curabitur vitae nunc sed. Facilisis sed odio morbi quis.")
|
||||
|
||||
keyboard.leader_mode = LeaderMode.TIMEOUT
|
||||
keyboard.leader_dictionary = {
|
||||
'hello': send_string('hello world from kmk macros'),
|
||||
'wpm': WPM,
|
||||
'atf': emoticons.ANGRY_TABLE_FLIP,
|
||||
'tf': emoticons.TABLE_FLIP,
|
||||
'fca': emoticons.FLAG_CA,
|
||||
'fus': emoticons.FLAG_US,
|
||||
'cel': emoticons.CELEBRATORY_GLITTER,
|
||||
'shr': emoticons.SHRUGGIE,
|
||||
'poop': emoticons.POOP,
|
||||
}
|
||||
|
||||
_______ = KC.TRNS
|
||||
xxxxxxx = KC.NO
|
||||
HELLA_TD = KC.TD(
|
||||
KC.A,
|
||||
KC.B,
|
||||
# send_string('macros in a tap dance? I think yes'),
|
||||
send_string('macros in a tap dance? I think yes'),
|
||||
KC.TG(1),
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user