code.py
 1  # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  """CircuitPython Capacitive Touch HID Example for Neo Trinkey"""
 6  import time
 7  import board
 8  import touchio
 9  import usb_hid
10  from adafruit_hid.keyboard import Keyboard
11  from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
12  from adafruit_hid.keycode import Keycode
13  
14  keyboard = Keyboard(usb_hid.devices)
15  keyboard_layout = KeyboardLayoutUS(keyboard)
16  
17  touch1 = touchio.TouchIn(board.TOUCH1)
18  touch2 = touchio.TouchIn(board.TOUCH2)
19  
20  while True:
21      if touch1.value:  # If touch pad 1 is touched...
22          while touch1.value:  # Wait for release...
23              time.sleep(0.1)
24          keyboard.send(Keycode.SHIFT, Keycode.A)  # Then send key press.
25  
26      if touch2.value:  # If touch pad 2 is touched...
27          while touch2.value:  # Wait for release...
28              time.sleep(0.1)
29          keyboard_layout.write("Hello World!\n")  # Then send string.