# stko: copied from # SPDX-FileCopyrightText: 2021 John Park for Adafruit Industries # SPDX-License-Identifier: MIT # RaspberryPi Pico RP2040 Mechanical Keyboard import time import board from digitalio import DigitalInOut, Direction, Pull import usb_hid from adafruit_hid.keyboard import Keyboard from adafruit_hid.keycode import Keycode print("---Pico Joystick emulator Keyboard---") led = DigitalInOut(board.LED) led.direction = Direction.OUTPUT led.value = True kbd = Keyboard(usb_hid.devices) pins = [ board.GP28, # black board.GP27, # red board.GP26, # green board.GP15, # blue board.GP14, # yellow ] keymap = [ Keycode.L, # Keycode.X, Keycode.C, Keycode.Y, # should be Keycode.Z, but to adjust it to german keyboard settings... Keycode.V, ] nr_of_keys = len(keymap) switches = [] switch_state = [] for i in range(nr_of_keys): switch_state.append(0) switches.append(DigitalInOut(pins[i])) switches[i].direction = Direction.INPUT switches[i].pull = Pull.UP while True: for button in range(nr_of_keys): if switch_state[button] == 0: if not switches[button].value: print(button, "on") try: # kbd.press(keymap[button]) kbd.send(Keycode.CONTROL, keymap[button]) except ValueError: # deals w six key limit print("e1") pass switch_state[button] = 1 if switch_state[button] == 1: if switches[button].value: print(button, "off") try: pass # kbd.release(keymap[button]) except ValueError: print("e1") pass switch_state[button] = 0 time.sleep(0.01) # debounce