Skip to content

Instantly share code, notes, and snippets.

@r41d
Last active May 13, 2025 12:30
Show Gist options
  • Save r41d/bbce35f0c32a7a672b5a60cb1c2c7871 to your computer and use it in GitHub Desktop.
Save r41d/bbce35f0c32a7a672b5a60cb1c2c7871 to your computer and use it in GitHub Desktop.
# Dependencies:
# 1. Repo: https://github.com/adafruit/Adafruit_CircuitPython_HID
# Install: copy adafruit_hid folder to lib/ folder on the Pi Pico
# 2. Repo: https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel
# Install: copy neopixel.py folder to lib/ folder on the Pi Pico
import time
import board
import digitalio
from neopixel import NeoPixel
import usb_hid
from adafruit_hid.keyboard import Keyboard
# from adafruit_hid.keycode import Keycode
button = digitalio.DigitalInOut(board.GP28) # connected to button
button.switch_to_input(pull=digitalio.Pull.DOWN)
pixels = NeoPixel(board.NEOPIXEL, 1)
kbd = Keyboard(usb_hid.devices)
def button_down_event():
print("DownPress event")
kbd.send(0x73) # F24
# Windows: kbd.press(Keycode.LEFT_GUI, Keycode.L)
if __name__ == "__main__":
last = button.value
while True:
pixels[0] = (100 if button.value else 0, 0, 0)
if button.value and not last:
button_down_event()
if not button.value and last:
print("Button up event")
last = button.value
time.sleep(0.01)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment