Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The Payload

Structure

As seen on the last page, the payload is defined in src/inputs.py and selected by setting the payload variable in code.py.

Let’s look at an example:

# src/inputs.py
hello_world = [
    ("SLEEP", 0.2),
    ("LED", (0,255,0)),
    ("SLEEP", 0.2),
    ("WRITE", "Hello World"),
    ("SLEEP", 0.1),
]

# code.py
payload = inputs.hello_world

This script first sets the color of the on-board LED to an RGB value, then types out Hello World.

There are multiple actions used here — let’s look at all of them:

KeyValue
SLEEPSleep for v seconds
PRESSPress and hold key v (Adafruit HID keycode: Keycode.<key>)
SENDPress and release key v (Adafruit HID keycode: Keycode.<key>)
WRITEType out the string v
RELEASERelease all keys. No value needed, so set to None
LEDChange the LED color to RGB tuple v