Add support for millisecond delays within a macro sequence
This commit is contained in:
parent
2c05efa805
commit
fde9b7e274
@ -40,12 +40,15 @@ class RawKeycodes:
|
|||||||
|
|
||||||
KC_UC_MODE = 1109
|
KC_UC_MODE = 1109
|
||||||
|
|
||||||
|
KC_MACRO_SLEEP_MS = 1110
|
||||||
|
|
||||||
|
|
||||||
# These shouldn't have all the fancy shenanigans Keycode allows
|
# These shouldn't have all the fancy shenanigans Keycode allows
|
||||||
# such as no_press, because they modify KMK internal state in
|
# such as no_press, because they modify KMK internal state in
|
||||||
# ways we need to tightly control. Thus, we can get away with
|
# ways we need to tightly control. Thus, we can get away with
|
||||||
# a lighter-weight namedtuple implementation here
|
# a lighter-weight namedtuple implementation here
|
||||||
LayerKeycode = namedtuple('LayerKeycode', ('code', 'layer'))
|
LayerKeycode = namedtuple('LayerKeycode', ('code', 'layer'))
|
||||||
|
MacroSleepKeycode = namedtuple('MacroSleepKeycode', ('code', 'ms'))
|
||||||
|
|
||||||
|
|
||||||
class UnicodeModeKeycode(namedtuple('UnicodeModeKeycode', ('code', 'mode'))):
|
class UnicodeModeKeycode(namedtuple('UnicodeModeKeycode', ('code', 'mode'))):
|
||||||
@ -455,6 +458,10 @@ class KMK(KeycodeCategory):
|
|||||||
)
|
)
|
||||||
KC_UC_MODE_WINC = UnicodeModeKeycode.from_mode_const(UnicodeModes.WINC)
|
KC_UC_MODE_WINC = UnicodeModeKeycode.from_mode_const(UnicodeModes.WINC)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def KC_MACRO_SLEEP_MS(ms):
|
||||||
|
return MacroSleepKeycode(RawKeycodes.KC_MACRO_SLEEP_MS, ms)
|
||||||
|
|
||||||
|
|
||||||
class Layers(KeycodeCategory):
|
class Layers(KeycodeCategory):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -2,13 +2,18 @@ import string
|
|||||||
|
|
||||||
from kmk.common.event_defs import (hid_report_event, keycode_down_event,
|
from kmk.common.event_defs import (hid_report_event, keycode_down_event,
|
||||||
keycode_up_event)
|
keycode_up_event)
|
||||||
from kmk.common.keycodes import Keycodes, char_lookup
|
from kmk.common.keycodes import Keycodes, RawKeycodes, char_lookup
|
||||||
from kmk.common.macros import KMKMacro
|
from kmk.common.macros import KMKMacro
|
||||||
|
from kmk.common.util import sleep_ms
|
||||||
|
|
||||||
|
|
||||||
def simple_key_sequence(seq):
|
def simple_key_sequence(seq):
|
||||||
def _simple_key_sequence(state):
|
def _simple_key_sequence(state):
|
||||||
for key in seq:
|
for key in seq:
|
||||||
|
if key.code == RawKeycodes.KC_MACRO_SLEEP_MS:
|
||||||
|
sleep_ms(key.ms)
|
||||||
|
continue
|
||||||
|
|
||||||
if not getattr(key, 'no_press', None):
|
if not getattr(key, 'no_press', None):
|
||||||
yield keycode_down_event(key)
|
yield keycode_down_event(key)
|
||||||
yield hid_report_event()
|
yield hid_report_event()
|
||||||
|
@ -29,3 +29,16 @@ def reset_bootloader():
|
|||||||
import microcontroller
|
import microcontroller
|
||||||
microcontroller.on_next_reset(microcontroller.RunMode.BOOTLOADER)
|
microcontroller.on_next_reset(microcontroller.RunMode.BOOTLOADER)
|
||||||
microcontroller.reset()
|
microcontroller.reset()
|
||||||
|
|
||||||
|
|
||||||
|
def sleep_ms(ms):
|
||||||
|
'''
|
||||||
|
Tries to sleep for a number of milliseconds in a cross-implementation
|
||||||
|
way. Will raise an ImportError if time is not available on the platform.
|
||||||
|
'''
|
||||||
|
try:
|
||||||
|
import time
|
||||||
|
time.sleep_ms(ms)
|
||||||
|
except AttributeError:
|
||||||
|
import time
|
||||||
|
time.sleep(ms / 1000)
|
||||||
|
@ -22,6 +22,8 @@ MACRO_TEST_SIMPLE = simple_key_sequence([
|
|||||||
|
|
||||||
KC.SPACE,
|
KC.SPACE,
|
||||||
|
|
||||||
|
KC.MACRO_SLEEP_MS(500),
|
||||||
|
|
||||||
KC.LSHIFT(KC.K),
|
KC.LSHIFT(KC.K),
|
||||||
KC.LSHIFT(KC.M),
|
KC.LSHIFT(KC.M),
|
||||||
KC.LSHIFT(KC.K),
|
KC.LSHIFT(KC.K),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user