Allow strings in keymap. Replace with keys in keyboard _init cycle.
This commit is contained in:
parent
a4d6a44a04
commit
9f964aba36
@ -73,6 +73,13 @@ print(dir(board))
|
|||||||
keyboard.keymap = [[KC.A, KC.B]]
|
keyboard.keymap = [[KC.A, KC.B]]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- You can also define the keymap with strings. They get replaced with `Key` objects
|
||||||
|
when the keyboard is started:
|
||||||
|
|
||||||
|
```python
|
||||||
|
keyboard.keymap = [['A', 'B']]
|
||||||
|
```
|
||||||
|
|
||||||
You can further define a bunch of other stuff:
|
You can further define a bunch of other stuff:
|
||||||
|
|
||||||
- `keyboard.debug_enabled` which will spew a ton of debugging information to the serial
|
- `keyboard.debug_enabled` which will spew a ton of debugging information to the serial
|
||||||
|
@ -19,8 +19,8 @@ mergulhar!
|
|||||||
ter problemas de corrupção. ou você pode estar em um dia ruim e apagar o
|
ter problemas de corrupção. ou você pode estar em um dia ruim e apagar o
|
||||||
arquivo errado.
|
arquivo errado.
|
||||||
|
|
||||||
- Atribuir uma instância `KMKKeyboard` a uma variável, por exemplo, `keyboard =
|
- Atribuir uma instância `KMKKeyboard` a uma variável, por exemplo,
|
||||||
KMKKeyboard()` (note os parênteses).
|
`keyboard = KMKKeyboard()` (note os parênteses).
|
||||||
|
|
||||||
- Certificar-se quie esta instância de `KMKKeyboard` é realmente executada ao
|
- Certificar-se quie esta instância de `KMKKeyboard` é realmente executada ao
|
||||||
fim do arquivo usando um bloco como este:
|
fim do arquivo usando um bloco como este:
|
||||||
@ -75,6 +75,13 @@ print(dir(board))
|
|||||||
keyboard.keymap = [[KC.A, KC.B]]
|
keyboard.keymap = [[KC.A, KC.B]]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- Você também pode definir o mapa de teclas com strings. Eles são substituídos por
|
||||||
|
`Key` objetos quando o teclado é iniciado:
|
||||||
|
|
||||||
|
```python
|
||||||
|
keyboard.keymap = [['A', 'B']]
|
||||||
|
```
|
||||||
|
|
||||||
Você pode definir um monte de outras coisas
|
Você pode definir um monte de outras coisas
|
||||||
|
|
||||||
- `keyboard.debug_enabled` que vai atirar um monte de informação de depuração
|
- `keyboard.debug_enabled` que vai atirar um monte de informação de depuração
|
||||||
|
@ -293,6 +293,15 @@ class KMKKeyboard:
|
|||||||
cm.extend(m.coord_mapping)
|
cm.extend(m.coord_mapping)
|
||||||
self.coord_mapping = tuple(cm)
|
self.coord_mapping = tuple(cm)
|
||||||
|
|
||||||
|
def _init_replace_strings_in_keymap_with_keys(self):
|
||||||
|
for _, layer in enumerate(self.keymap):
|
||||||
|
for key_idx, key in enumerate(layer):
|
||||||
|
if isinstance(key, str):
|
||||||
|
replacement = KC[key]
|
||||||
|
layer[key_idx] = replacement
|
||||||
|
if self.debug_enabled:
|
||||||
|
print(f"Replacing '{key}' with {replacement}")
|
||||||
|
|
||||||
def _init_hid(self):
|
def _init_hid(self):
|
||||||
if self.hid_type == HIDModes.NOOP:
|
if self.hid_type == HIDModes.NOOP:
|
||||||
self._hid_helper = AbstractHID
|
self._hid_helper = AbstractHID
|
||||||
@ -475,6 +484,7 @@ class KMKKeyboard:
|
|||||||
self._init_sanity_check()
|
self._init_sanity_check()
|
||||||
self._init_hid()
|
self._init_hid()
|
||||||
self._init_matrix()
|
self._init_matrix()
|
||||||
|
self._init_replace_strings_in_keymap_with_keys()
|
||||||
self._init_coord_mapping()
|
self._init_coord_mapping()
|
||||||
|
|
||||||
for module in self.modules:
|
for module in self.modules:
|
||||||
|
@ -10,6 +10,19 @@ class TestKmkKeyboard(unittest.TestCase):
|
|||||||
|
|
||||||
keyboard.test('Simple key press', [(0, True), (0, False)], [{KC.N1}, {}])
|
keyboard.test('Simple key press', [(0, True), (0, False)], [{KC.N1}, {}])
|
||||||
|
|
||||||
|
def test_basic_kmk_keyboard_replace_string_primary_name(self):
|
||||||
|
keyboard = KeyboardTest([], [['1', '2', '3', '4']])
|
||||||
|
|
||||||
|
keyboard.test('Simple key press', [(0, True), (0, False)], [{KC.N1}, {}])
|
||||||
|
|
||||||
|
def test_basic_kmk_keyboard_replace_string_secondary_name(self):
|
||||||
|
keyboard = KeyboardTest([], [['N1', 'N2', 'N3', 'N4']])
|
||||||
|
|
||||||
|
keyboard.test('Simple key press', [(0, True), (0, False)], [{KC.N1}, {}])
|
||||||
|
|
||||||
|
def test_basic_kmk_keyboard_unknown_replacement_string(self):
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
KeyboardTest([], [['UNKNOWN1', 'UNKNOWN2', 'UNKNOWN3', 'UNKNOWN4']])
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user