import machine
import time
import usb_hid
from machine import Pin
# Pin declaration for the button (assuming the button is connected to GP15)
button = Pin(15, Pin.IN, Pin.PULL_DOWN)
# HID keyboard report descriptor
KEYBOARD = 1
keyboard_report = bytearray(8)
def send_report(report):
usb_hid.device.send_report(report, KEYBOARD)
# Press enter key (Enter key code is 0x28)
def press_enter():
keyboard_report[2] = 0x28
send_report(keyboard_report)
print("Enter key pressed")
# Release all keys
def release_keys():
keyboard_report[2] = 0x00
send_report(keyboard_report)
print("Keys released")
# Main loop
while True:
if button.value():
press_enter()
time.sleep(0.1) # Debounce delay
release_keys()
time.sleep(0.1) # Prevent repeated pressing
time.sleep(0.01) # Loop delay