Last active
March 16, 2024 19:51
-
-
Save dglaude/6f2a3f9c3c1e2f1bdf055245f1a2edb7 to your computer and use it in GitHub Desktop.
Keyboard mapping CardPuter Card Computer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
K.APPLICATION | |
K.Z | |
K.C | |
K.B | |
K.M | |
K.DOWN_ARROW | |
K.SPACEBAR | |
K.CAPS_LOCK | |
K.S | |
K.F | |
K.H | |
K.K | |
K.UP_ARROW | |
K.RETURN | |
K.Q | |
K.E | |
K.T | |
K.U | |
K.O | |
K.LEFT_BRACKET | |
K.BACKSLASH | |
K.ONE | |
K.THREE | |
K.FIVE | |
K.SEVEN | |
K.NINE | |
K.MINUS | |
K.BACKSPACE | |
K.LEFT_CONTROL | |
K.LEFT_ALT | |
K.X | |
K.V | |
K.N | |
K.LEFT_ARROW | |
K.RIGHT_ARROW | |
None | |
K.A | |
K.D | |
K.G | |
K.J | |
K.L | |
K.QUOTE | |
K.TAB | |
K.W | |
K.R | |
K.Y | |
K.I | |
K.P | |
K.RIGHT_BRACKET | |
K.ESCAPE | |
K.TWO | |
K.FOUR | |
K.SIX | |
K.EIGHT | |
K.ZERO | |
K.EQUALS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Test code for keycodes of cardputer = card computer | |
# | |
# Merge between: | |
# * Code for https://learn.adafruit.com/ibm-pc-keyboard-to-usb-hid-with-circuitpython/coding-the-keyboard | |
# IBM Keyboard to USB Adapter (MIT) Copyright 2022 Jeff Epler for Adafruit Industries | |
# * Demo code for DemuxKeyMatrix part of keypad (should move to own module) by CDario (@EDario) | |
# * Self created keycodes | |
import array | |
import board | |
import usb_hid | |
from adafruit_hid.keyboard import Keyboard | |
from adafruit_hid.keycode import Keycode as K | |
import board | |
import keypad | |
kbd = Keyboard(usb_hid.devices) | |
km = keypad.DemuxKeyMatrix( | |
row_addr_pins = (board.KB_A_0, board.KB_A_1, board.KB_A_2), | |
column_pins = (board.KB_COL_0, board.KB_COL_1, board.KB_COL_2, board.KB_COL_3, board.KB_COL_4, board.KB_COL_5, board.KB_COL_6) | |
) | |
# fmt: off | |
cardputer_keycodes = [ | |
K.APPLICATION, | |
K.Z, | |
K.C, | |
K.B, | |
K.M, | |
K.DOWN_ARROW, | |
K.SPACEBAR, | |
K.CAPS_LOCK, | |
K.S, | |
K.F, | |
K.H, | |
K.K, | |
K.UP_ARROW, | |
K.RETURN, | |
K.Q, | |
K.E, | |
K.T, | |
K.U, | |
K.O, | |
K.LEFT_BRACKET, | |
K.BACKSLASH, | |
K.ONE, | |
K.THREE, | |
K.FIVE, | |
K.SEVEN, | |
K.NINE, | |
K.MINUS, | |
K.BACKSPACE, | |
K.LEFT_CONTROL, | |
K.LEFT_ALT, | |
K.X, | |
K.V, | |
K.N, | |
K.LEFT_ARROW, | |
K.RIGHT_ARROW, | |
None, | |
K.A, | |
K.D, | |
K.G, | |
K.J, | |
K.L, | |
K.QUOTE, | |
K.TAB, | |
K.W, | |
K.R, | |
K.Y, | |
K.I, | |
K.P, | |
K.RIGHT_BRACKET, | |
K.ESCAPE, | |
K.TWO, | |
K.FOUR, | |
K.SIX, | |
K.EIGHT, | |
K.ZERO, | |
K.EQUALS, | |
] | |
# fmt: on | |
event = keypad.Event() | |
while True: | |
if km.events.get_into(event): | |
keycode = cardputer_keycodes[event.key_number] | |
print(f"{keycode} {'PRESSED' if event.pressed else 'released'}") | |
if keycode is None: | |
continue | |
if event.pressed: | |
kbd.press(keycode) | |
else: | |
kbd.release(keycode) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Order KeyID KeySymbole Remark | |
0 49 K.ESCAPE | |
1 21 K.ONE | |
2 50 K.TWO | |
3 22 K.THREE | |
4 51 K.FOUR | |
5 23 K.FIVE | |
6 52 K.SIX | |
7 24 K.SEVEN | |
8 53 K.EIGHT | |
9 25 K.NINE | |
10 54 K.ZERO | |
11 26 K.MINUS | |
12 55 K.EQUALS | |
13 27 K.BACKSPACE | |
14 42 K.TAB | |
15 14 K.Q | |
16 43 K.W | |
17 15 K.E | |
18 44 K.R | |
19 16 K.T | |
20 45 K.Y | |
21 17 K.U | |
22 46 K.I | |
23 18 K.O | |
24 47 K.P | |
25 19 K.LEFT_BRACKET | |
26 48 K.RIGHT_BRACKET | |
27 20 K.BACKSLASH | |
28 35 None fn | |
29 7 K.CAPS_LOCK | |
30 36 K.A | |
31 8 K.S | |
32 37 K.D | |
33 9 K.F | |
34 38 K.G | |
35 10 K.H | |
36 39 K.J | |
37 11 K.K | |
38 40 K.L | |
39 12 K.UP_ARROW | |
40 41 K.QUOTE | |
41 13 K.RETURN | |
42 28 K.LEFT_CONTROL | |
43 0 K.APPLICATION OPT | |
44 29 K.LEFT_ALT | |
45 1 K.Z | |
46 30 K.X | |
47 2 K.C | |
48 31 K.V | |
49 3 K.B | |
50 32 K.N | |
51 4 K.M | |
52 33 K.LEFT_ARROW | |
53 5 K.DOWN_ARROW | |
54 34 K.RIGHT_ARROW | |
55 6 K.SPACEBAR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment