Created
February 16, 2022 19:57
-
-
Save seancmonahan/e45643482fe289b2f33bf7fbbf41c4f4 to your computer and use it in GitHub Desktop.
CircuitPython "keyboard" to type in a public key into the Raspberry Pi network installer
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
'''CircuitPython script that simulates a USB keyboard. It waits 5 seconds, and then | |
types in the contents of the string `public_key`. I wanted a way to easily enter | |
my SSH public key without manually typing it into the Raspberry Pi network installer. | |
Requires `adafruit_hid` from the Adafruit CircuitPython Bundle: | |
https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases | |
For a Raspberry Pi Pico running CircuitPython, I used | |
https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases/download/20220216/adafruit-circuitpython-bundle-7.x-mpy-20220216.zip | |
To install the adafruit_hid package, extract the zip, and then | |
copy the `adafruit_hid` directory from the unzipped lib/ into your Pi Pico's lib/ directory. | |
''' | |
public_key = '''WHAT YOU WANT TO TYPE GOES HERE. E.g. the contents of your PUBLIC ssh key''' | |
# public_key = '''ssh-ed25519 AJUMBLEOFLETTERSANDNUMBERS... username@host''' | |
import time | |
import usb_hid | |
from adafruit_hid.keyboard import Keyboard | |
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS | |
kbd = Keyboard(usb_hid.devices) | |
kbdl = KeyboardLayoutUS(kbd) | |
time.sleep(5.0) # Wait 5.0 seconds for everything to get ready | |
for letter in public_key: | |
kbd.send(*kbdl.keycodes(letter)) | |
time.sleep(0.01) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment