import digitalio
import board
import time

import neopixel

import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode

pixels = neopixel.NeoPixel(board.NEOPIXEL, 12, brightness=0.2)

first_key = digitalio.DigitalInOut(board.KEY1)
first_key.pull = digitalio.Pull.UP

keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayoutUS(keyboard)  # We're in the US :)

# print(dir(Keycode))

key_up = True
while True:
    pressed = not first_key.value
    if not pressed and not key_up:
        pixels.fill(0x000000)
        key_up = True
        print("up")
        keyboard.release_all()
    elif pressed and key_up:
        pixels.fill(0xff0000)
        print("down")
        key_up = False
        # KEYPAD_ONE doesn't work because we may need numlock
        keyboard.press(Keycode.ONE)