#!/usr/bin/env python3

from evdev import UInput, ecodes
import time
import sys

def execute(command: str, uinput: UInput):
    split_command = command.split(" ")
    if split_command[0] == "press":
        uinput.write(ecodes.EV_KEY, int(split_command[1]), 1)
        uinput.syn()
    elif split_command[0] == "release":
        uinput.write(ecodes.EV_KEY, int(split_command[1]), 0)
        uinput.syn()
    elif split_command[0] == "sleep":
        time.sleep(float(split_command[1]))

uinput = UInput({ecodes.EV_KEY: list(range(1, 0x2ff))})

if len(sys.argv) == 1:
    for command in sys.stdin:
        execute(command, uinput)
else:
    for command in sys.argv[1:]:
        execute(command, uinput)
