This example has been updated for version 4+ of the CircuitPython HID library. On the CircuitPlayground Express this library is built into CircuitPython. So, please use the latest version of CircuitPython as well. (At least 5.0.0-beta.3)

Our next step is to pull in the HID library and send keys instead of beeping. The GBoard app accepts '.' (period) and '-' (minus sign), for dots and dashes, respectively, so that's what we'll send.

The changes are that we import the Keyboard and Keycode modules from the HID library, and initialize a keyboard object that is then used to send keys to the connected device.

For setting up the keyboard we need to add:

from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
import usb_hid
kbd = Keyboard(usb_hid.devices)

To actually send keys, we replace the dot and dash tone generation with kbd.send(Keycode.PERIOD) and kbd.send(Keycode.MINUS)

The code is below, copy it to on your Circuit Playground Express.

# SPDX-FileCopyrightText: 2018 Dave Astels for Adafruit Industries
# SPDX-License-Identifier: MIT

Circuit Playground Express GBoard: capacitive touch generating keycodes

Adafruit invests time and resources providing this open source code.
Please support Adafruit and open source hardware by purchasing
products from Adafruit!

Written by Dave Astels for Adafruit Industries
Copyright (c) 2018 Adafruit Industries
Licensed under the MIT license.

All text above must be included in any redistribution.

import usb_hid
from import cpx
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode


kbd = Keyboard(usb_hid.devices)

# You can adjust this to get the level of sensitivity you want.

while True:
    if cpx.touch_A4:
        while cpx.touch_A4:
    elif cpx.touch_A3:
        while cpx.touch_A3:

Open up an app that accepts text. It can be a word processor like Google Docs or just be a text input box like the SMS/phone message app or a Twitter message input box.

Now, when you touch the A4 pad a dot will be sent, and when you touch the A3 pad a dash will be. The GBoard keyboard replacement will convert those dots and dashes into conventional characters and send them to the app.

You can refer to the table below for International and American Morse Code (via Wikipedia).

credit: Wikipedia

This guide was first published on Jul 24, 2018. It was last updated on Jul 24, 2018.

This page (Sending Keys) was last updated on Jun 15, 2022.

Text editor powered by tinymce.