Skip to content

Commit fa1a841

Browse files
authored
Merge pull request #1903 from dhalbert/pico-four-key-modifier
Pico_Four_Key: fix modifier and touch up style
2 parents 360bedd + 49a2d33 commit fa1a841

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

Pico_Four_Keypad/code.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,42 @@
1111

1212
kpd = Keyboard(usb_hid.devices)
1313

14+
# Choose the correct modifier key for Windows or Mac.
15+
# Comment one line and uncomment the other.
16+
# MODIFIER = Keycode.CONTROL # For Windows
17+
MODIFIER = Keycode.COMMAND # For Mac
18+
1419
# define buttons
15-
num_keys = 4
16-
pins = (
20+
NUM_KEYS = 4
21+
PINS = (
1722
board.GP0,
1823
board.GP1,
1924
board.GP2,
20-
board.GP3
25+
board.GP3,
26+
)
27+
28+
KEYMAP = (
29+
("Select all", [MODIFIER, Keycode.A]),
30+
("Cut", [MODIFIER, Keycode.X]),
31+
("Copy", [MODIFIER, Keycode.C]),
32+
("Paste", [MODIFIER, Keycode.V]),
2133
)
2234

2335
keys = []
24-
for pin in pins:
25-
tmp_pin = DigitalInOut(pin)
26-
tmp_pin.pull = Pull.UP
27-
keys.append(Debouncer(tmp_pin))
28-
29-
keymap = {
30-
(0): ("Select all", [Keycode.GUI, Keycode.A]),
31-
(1): ("Cut", [Keycode.GUI, Keycode.X]),
32-
(2): ("Copy", [Keycode.GUI, Keycode.C]),
33-
(3): ("Paste", [Keycode.GUI, Keycode.V])
34-
}
36+
for pin in PINS:
37+
dio = DigitalInOut(pin)
38+
dio.pull = Pull.UP
39+
keys.append(Debouncer(dio))
3540

3641
print("\nWelcome to keypad")
3742
print("keymap:")
38-
for k in range(num_keys):
39-
print("\t", (keymap[k][0]))
43+
for k in range(NUM_KEYS):
44+
print("\t", (KEYMAP[k][0]))
4045

4146

4247
while True:
43-
for i in range(num_keys):
48+
for i in range(NUM_KEYS):
4449
keys[i].update()
4550
if keys[i].fell:
46-
print(keymap[i][0])
47-
kpd.send(*keymap[i][1])
51+
print(KEYMAP[i][0])
52+
kpd.send(*KEYMAP[i][1])

0 commit comments

Comments
 (0)