kmk_firmware/kmk/common/keymap.py

26 lines
828 B
Python
Raw Normal View History

from kmk.common.event_defs import key_down_event, key_up_event
2018-09-03 13:22:52 +02:00
class Keymap:
def __init__(self, map):
self.map = map
2018-09-03 13:22:52 +02:00
def parse(self, matrix, store):
state = store.get_state()
for ridx, row in enumerate(matrix):
for cidx, col in enumerate(row):
if col != state.matrix[ridx][cidx]:
2018-09-03 13:22:52 +02:00
if col:
store.dispatch(key_down_event(
row=ridx,
col=cidx,
keycode=self.map[ridx][cidx],
))
2018-09-03 13:22:52 +02:00
else:
store.dispatch(key_up_event(
row=ridx,
col=cidx,
keycode=self.map[ridx][cidx],
))