Support a simple macro of a sequence of keycodes (basis for SEND_STRING)

This commit is contained in:
Josh Klar
2018-09-30 18:03:43 -07:00
parent 99573de217
commit bdd4f86472
6 changed files with 134 additions and 10 deletions

View File

@@ -9,6 +9,9 @@ KEY_DOWN_EVENT = const(2)
INIT_FIRMWARE_EVENT = const(3)
NEW_MATRIX_EVENT = const(4)
HID_REPORT_EVENT = const(5)
KEYCODE_UP_EVENT = const(6)
KEYCODE_DOWN_EVENT = const(7)
MACRO_COMPLETE_EVENT = const(8)
logger = logging.getLogger(__name__)
@@ -39,6 +42,28 @@ def key_down_event(row, col):
}
def keycode_up_event(keycode):
'''
Press a key by Keycode object, bypassing the keymap. Used mostly for
macros.
'''
return {
'type': KEYCODE_UP_EVENT,
'keycode': keycode,
}
def keycode_down_event(keycode):
'''
Release a key by Keycode object, bypassing the keymap. Used mostly for
macros.
'''
return {
'type': KEYCODE_DOWN_EVENT,
'keycode': keycode,
}
def new_matrix_event(matrix):
return {
'type': NEW_MATRIX_EVENT,
@@ -52,6 +77,13 @@ def hid_report_event():
}
def macro_complete_event(macro):
return {
'type': MACRO_COMPLETE_EVENT,
'macro': macro,
}
def matrix_changed(new_matrix):
def _key_pressed(dispatch, get_state):
state = get_state()
@@ -94,4 +126,12 @@ def matrix_changed(new_matrix):
except ImportError:
logger.warning('Tried to reset to bootloader, but not supported on this chip?')
while get_state().macros_pending:
macro = get_state().macros_pending[0]
for event in macro():
dispatch(event)
dispatch(macro_complete_event(macro))
return _key_pressed