import busio import board from board import * from rainbowio import colorwheel import waveshare_LCD1602 from digitalio import DigitalInOut, Direction, Pull import time import board import usb_hid from adafruit_hid.keyboard import Keyboard from keyboard_layout_win_uk import KeyboardLayout from keycode_win_uk import Keycode """Default I2C ports on boards that have one""" i2c = busio.I2C(GP19, GP18) buttonOne = DigitalInOut(board.GP0) buttonOne.pull = Pull.UP buttonTwo = DigitalInOut(board.GP1) buttonTwo.pull = Pull.UP buttonThree = DigitalInOut(board.GP2) buttonThree.pull = Pull.UP buttonFour = DigitalInOut(board.GP3) buttonFour.pull = Pull.UP buttonFive = DigitalInOut(board.GP4) buttonFive.pull = Pull.UP buttonSix = DigitalInOut(board.GP5) buttonSix.pull = Pull.UP kbd = Keyboard(usb_hid.devices) layout = KeyboardLayout(kbd) lcd = waveshare_LCD1602.LCD1602(i2c, 16, 2) lcd.setCursor(0,0) def macro_parser(macroFileName=(str)): file = open("macros/" + macroFileName, 'r') clearScr = 1 lineToShow = "" holdingKeys = 0 sendCombo = 0 keysToPress = [] for line in file: print(line) line = line.replace("\n", "") workingLine = line sleepingTime = 0 if line == "HOLD": holdingKeys = 1 if line == "RELEASE": if holdingKeys == 1: sendCombo = 1 if sendCombo == 1: if len(keysToPress) == 1: kbd.send(keysToPress[0]) kbd.release_all() elif len(keysToPress) == 2: kbd.send(keysToPress[0], keysToPress[1]) kbd.release_all() elif len(keysToPress) == 3: kbd.send(keysToPress[0], keysToPress[1], keysToPress[2]) kbd.release_all() elif len(keysToPress) == 4: kbd.send(keysToPress[0], keysToPress[1], keysToPress[2], keysToPress[3]) kbd.release_all() elif len(keysToPress) == 5: kbd.send(keysToPress[0], keysToPress[1], keysToPress[2], keysToPress[3], keysToPress[4]) kbd.release_all() elif len(keysToPress) == 6: kbd.send(keysToPress[0], keysToPress[1], keysToPress[2], keysToPress[3], keysToPress[4], keysToPress[5]) kbd.release_all() sendCombo = 0 holdingKeys = 0 keysToPress = [] if line == "super": if holdingKeys == 1: keysToPress.append(Keycode.WINDOWS) else: time.sleep(0.1) kbd.send(Keycode.WINDOWS) if line == "escape": if holdingKeys == 1: keysToPress.append(Keycode.ESCAPE) else: time.sleep(0.1) kbd.send(Keycode.ESCAPE) if line == "tab": if holdingKeys == 1: keysToPress.append(Keycode.TAB) else: time.sleep(0.1) kbd.send(Keycode.TAB) if line == "f24": if holdingKeys == 1: keysToPress.append(Keycode.F24) else: time.sleep(0.1) kbd.send(Keycode.F24) if line == "f23": if holdingKeys == 1: keysToPress.append(Keycode.F23) else: time.sleep(0.1) kbd.send(Keycode.F23) if line == "f22": if holdingKeys == 1: keysToPress.append(Keycode.F22) else: time.sleep(0.1) kbd.send(Keycode.F22) if line == "f21": if holdingKeys == 1: keysToPress.append(Keycode.F21) else: time.sleep(0.1) kbd.send(Keycode.F21) if line == "f20": if holdingKeys == 1: keysToPress.append(Keycode.F20) else: time.sleep(0.1) kbd.send(Keycode.F20) if line == "f19": if holdingKeys == 1: keysToPress.append(Keycode.F19) else: time.sleep(0.1) kbd.send(Keycode.F19) if line == "f18": if holdingKeys == 1: keysToPress.append(Keycode.F18) else: time.sleep(0.1) kbd.send(Keycode.F18) if line == "f17": if holdingKeys == 1: keysToPress.append(Keycode.F17) else: time.sleep(0.1) kbd.send(Keycode.F17) if line == "f16": if holdingKeys == 1: keysToPress.append(Keycode.F16) else: time.sleep(0.1) kbd.send(Keycode.F16) if line == "f15": if holdingKeys == 1: keysToPress.append(Keycode.F15) else: time.sleep(0.1) kbd.send(Keycode.F15) if line == "f14": if holdingKeys == 1: keysToPress.append(Keycode.F14) else: time.sleep(0.1) kbd.send(Keycode.F14) if line == "f13": if holdingKeys == 1: keysToPress.append(Keycode.F13) else: time.sleep(0.1) kbd.send(Keycode.F13) if line == "f12": if holdingKeys == 1: keysToPress.append(Keycode.F12) else: time.sleep(0.1) kbd.send(Keycode.F12) if line == "f11": if holdingKeys == 1: keysToPress.append(Keycode.F11) else: time.sleep(0.1) kbd.send(Keycode.F11) if line == "f10": if holdingKeys == 1: keysToPress.append(Keycode.F10) else: time.sleep(0.1) kbd.send(Keycode.F10) if line == "f9": if holdingKeys == 1: keysToPress.append(Keycode.F9) else: time.sleep(0.1) kbd.send(Keycode.F9) if line == "f8": if holdingKeys == 1: keysToPress.append(Keycode.F8) else: time.sleep(0.1) kbd.send(Keycode.F8) if line == "f7": if holdingKeys == 1: keysToPress.append(Keycode.F7) else: time.sleep(0.1) kbd.send(Keycode.F7) if line == "f6": if holdingKeys == 1: keysToPress.append(Keycode.F6) else: time.sleep(0.1) kbd.send(Keycode.F6) if line == "f5": if holdingKeys == 1: keysToPress.append(Keycode.F5) else: time.sleep(0.1) kbd.send(Keycode.F5) if line == "f4": if holdingKeys == 1: keysToPress.append(Keycode.F4) else: time.sleep(0.1) kbd.send(Keycode.F4) if line == "f3": if holdingKeys == 1: keysToPress.append(Keycode.F3) else: time.sleep(0.1) kbd.send(Keycode.F3) if line == "f2": if holdingKeys == 1: keysToPress.append(Keycode.F2) else: time.sleep(0.1) kbd.send(Keycode.F2) if line == "f1": if holdingKeys == 1: keysToPress.append(Keycode.F1) else: time.sleep(0.1) kbd.send(Keycode.F1) if line == "windows": if holdingKeys == 1: keysToPress.append(Keycode.WINDOWS) else: time.sleep(0.1) kbd.send(Keycode.WINDOWS) if line == "ctrl": if holdingKeys == 1: keysToPress.append(Keycode.LEFT_CONTROL) else: time.sleep(0.1) kbd.send(Keycode.LEFT_CONTROL) if line == "shift": if holdingKeys == 1: keysToPress.append(Keycode.LEFT_SHIFT) else: time.sleep(0.1) kbd.send(Keycode.LEFT_SHIFT) if line.startswith("LCD_SHOW \""): line = line.replace("LCD_SHOW \"", "\"") line = line.replace('"', "") lineToShow = line clearScr = 0 if line.startswith("#"): pass if line == "": pass if line.startswith("WAIT"): line = line.replace("WAIT", "") line = line.replace(" ", "") sleepingTime = line clearScr = 1 if line.startswith('"') and line.endswith('"'): lineLength = len(line) tempLine = "" currentLine = line for i in range(0, lineLength): if i == 0: pass elif i != (lineLength - 1): tempLine = tempLine + currentLine[i] line = tempLine if holdingKeys == 0: layout.write(line) line = currentLine if len(tempLine) == 1: if holdingKeys == 1: keysToPress.append(layout.keycodes(tempLine)[0]) if line == "downarrow": if holdingKeys == 1: keysToPress.append(Keycode.DOWN_ARROW) else: time.sleep(0.1) kbd.send(Keycode.DOWN_ARROW) elif line == "uparrow": if holdingKeys == 1: keysToPress.append(Keycode.UP_ARROW) else: time.sleep(0.1) kbd.send(Keycode.UP_ARROW) elif line == "leftarrow": if holdingKeys == 1: keysToPress.append(Keycode.LEFT_ARROW) else: time.sleep(0.1) kbd.send(Keycode.LEFT_ARROW) elif line == "space": if holdingKeys == 1: keysToPress.append(Keycode.SPACE) else: time.sleep(0.1) kbd.send(Keycode.SPACE) elif line == "capslock": if holdingKeys == 1: keysToPress.append(Keycode.CAPS_LOCK) else: time.sleep(0.1) kbd.send(Keycode.CAPS_LOCK) elif line == "rightarrow": if holdingKeys == 1: keysToPress.append(Keycode.RIGHT_ARROW) else: time.sleep(0.1) kbd.send(Keycode.RIGHT_ARROW) elif line == "forwardslash": if holdingKeys == 1: keysToPress.append(Keycode.FORWARD_SLASH) else: time.sleep(0.1) kbd.send(Keycode.FORWARD_SLASH) elif line == "backslash": if holdingKeys == 1: keysToPress.append(Keycode.BACKSLASH) else: time.sleep(0.1) kbd.send(Keycode.BACKSLASH) elif line == "backspace": if holdingKeys == 1: keysToPress.append(Keycode.BACKSPACE) else: time.sleep(0.1) kbd.send(Keycode.BACKSPACE) elif line == "enter": if holdingKeys == 1: keysToPress.append(Keycode.ENTER) else: time.sleep(0.1) kbd.send(Keycode.ENTER) print("KEYS_PRESSED: " + str(len(keysToPress))) if clearScr == 1 and workingLine.startswith("WAIT "): lcd.clear() lcd.setCursor(0,1) lcd.printout("> "+workingLine) lcd.setCursor(0,0) lcd.printout(lineToShow) print(lineToShow) if lineToShow != "": lineToShow = "" else: lcd.clear() lcd.setCursor(0,1) lcd.printout("> "+workingLine) time.sleep(float(sleepingTime)) time.sleep(0.5) while True: lcd.setCursor(0,0) if not buttonOne.value: lcd.clear() lcd.setCursor(0,0) lcd.printout("Install Arch") time.sleep(1) lcd.clear() macro_parser("archinstall.mcr") lcd.clear() elif not buttonTwo.value: lcd.clear() lcd.setCursor(0,0) lcd.printout("Macro Syntax") time.sleep(1) lcd.clear() macro_parser("syntax.mcr") lcd.clear() elif not buttonThree.value: lcd.clear() lcd.setCursor(0,0) lcd.printout("Test Macro") time.sleep(1) lcd.clear() macro_parser("test.mcr") lcd.clear() elif not buttonFour.value: lcd.clear() lcd.setCursor(0,0) lcd.printout("TF2 Binds") time.sleep(1) lcd.clear() macro_parser("tf2binds.mcr") lcd.clear lcd.setCursor(0,0) lcd.printout("Kico v4") lcd.setCursor(0,1) lcd.printout("Hit a key!")