Datasheet

CircuitPython HID Keyboard
One of the things we baked into CircuitPython is 'HID' control - Keyboard and Mouse capabilities. This means a Circuit
Playground Express can act like a keyboard device and press keys, or a mouse and have it move the mouse around
and press buttons. This is really handy because even if you cannot adapt your software to work with hardware, there's
almost always a keyboard interface - so if you want to have a capacitive touch interface for a game, say, then keyboard
emulation can often get you going really fast!
You'll need to install the driver bundle which comes with Keyboard, Keycode and Mouse support (https://adafru.it/Bf2)
Then try running this example code which will set the Circuit Playground Express Button_A and Button_B as HID
keyboard "keys".
# CircuitPlaygroundExpress_HIDKeyboard
import time
import board
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
from digitalio import DigitalInOut, Direction, Pull
# A simple neat keyboard demo in circuitpython
# The button pins we'll use, each will have an internal pulldown
buttonpins = [board.BUTTON_A, board.BUTTON_B]
# our array of button objects
buttons = []
# The keycode sent for each button, will be paired with a control key
buttonkeys = [Keycode.A, "Hello World!\n"]
controlkey = Keycode.SHIFT
# the keyboard object!
# sleep for a bit to avoid a race condition on some systems
time.sleep(1)
kbd = Keyboard()
# we're americans :)
layout = KeyboardLayoutUS(kbd)
© Adafruit Industries https://learn.adafruit.com/adafruit-circuit-playground-express Page 148 of 211