import RPi.GPIO as GPIO
from pynput.keyboard import Controller, Key
import time

GPIO.setmode(GPIO.BCM)
keyboard = Controller()

# Setup
clock = 25
inputPins = [16, 6, 5, 19]
buttonKeys = [Key.up, Key.down, Key.left, Key.right]
delay = 0.03
GPIO.setup(PIN, GPIO.OUT)
for pins in inputPins:
    GPIO.setup(pins, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)

def keyboard():
    for pins in inputPins:
        if GPIO.input(inputPins[pins]) == HIGH:
            keyboard.press(button_keys[pins])
        else:
            keyboard.release(button_keys[pins])

def clock_speed():
    GPIO.output(clock, GPIO.HIGH)
    time.sleep(delay)
    GPIO.output(clock, GPIO.LOW)
    time.sleep(delay)

try:
    while True:
        if delay < 0:
            delay += 0.001
        elif delay > 0.03 or GPIO.input(16) == HIGH or GPIO.input(6) == HIGH:
            delay -= 0.001
        else:
            delay += 0.001
        keyboard()
        clock_speed()
except KeyboardInterrupt:
    GPIO.cleanup()