CircuitPython's touchio module makes it easy to use the two capacitive touch pads on the Neo Trinkey. Combined with the Adafruit CircuitPython HID library, you can use the touch pads as HID inputs. This means you can use your Neo Trinkey to send a single key press, combination of key presses, or strings to your computer when you touch the pads!

All the necessary modules and libraries for this example are included with CircuitPython for the Neo Trinkey, so you do not need to load any separate files onto your board.

Save the following as code.py on your CIRCUITPY drive.

You do not need to download the Project Bundle - all the necessary libraries are included in CircuitPython for Neo Trinkey!
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""CircuitPython Capacitive Touch HID Example for Neo Trinkey"""
import time
import board
import touchio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode

keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayoutUS(keyboard)

touch1 = touchio.TouchIn(board.TOUCH1)
touch2 = touchio.TouchIn(board.TOUCH2)

while True:
    if touch1.value:  # If touch pad 1 is touched...
        while touch1.value:  # Wait for release...
            time.sleep(0.1)
        keyboard.send(Keycode.SHIFT, Keycode.A)  # Then send key press.

    if touch2.value:  # If touch pad 2 is touched...
        while touch2.value:  # Wait for release...
            time.sleep(0.1)
        keyboard_layout.write("Hello World!\n")  # Then send string.

Now, open a text editor of your choice. Touch the pad labeled 1. Note that nothing happens, until you let go. "A" appears! Touch and let go of the pad labeled 2 - "Hello World!" appears followed by a newline!

First you import all the necessary modules and libraries to make them available for use in your code.

Next, you create the keyboard and keyboard_layout objects, followed by setting up the two touch pads.

Inside the loop, you check to see if touch pad 1 is touched. While it is being touched, the code waits - without this wait, it would spam the key press! Once the pad is no longer being touched, you send the key combination of shift+a to get "A".

Then, you do the same for touch pad 2, but instead of a sending a key combination, you send the string "Hello World!".

That's all there is to using CircuitPython and the Neo Trinkey's capacitive touch pads to emulate key presses and send strings!

This guide was first published on Apr 10, 2021. It was last updated on Apr 14, 2021.

This page (Capacitive Touch HID) was last updated on Mar 20, 2023.

Text editor powered by tinymce.