Created
December 30, 2021 20:37
-
-
Save FoamyGuy/9b3d7a76de453fd450b57e315367cd39 to your computer and use it in GitHub Desktop.
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
import supervisor | |
import usb_hid | |
from adafruit_hid.keyboard import Keyboard | |
from adafruit_hid.keycode import Keycode | |
kbd = Keyboard(usb_hid.devices) | |
def send_q(): | |
kbd.send(Keycode.Q) | |
def send_e(): | |
kbd.send(Keycode.E) | |
COMMAND_MAP = { | |
"q": send_q, | |
"e": send_e, | |
} | |
def serial_read(): | |
if supervisor.runtime.serial_bytes_available: | |
value = input() | |
print("you sent: %s" % value) | |
parts = value.split(" ") | |
if parts[0] in COMMAND_MAP.keys(): | |
if len(parts) > 1: | |
COMMAND_MAP[parts[0]](parts[1]) | |
else: | |
COMMAND_MAP[parts[0]]() | |
while True: | |
serial_read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment