Skip to content

Instantly share code, notes, and snippets.

@Atticuss
Last active May 17, 2019 23:59
Show Gist options
  • Save Atticuss/c6995d9350a16b7ed36efba504cbefe1 to your computer and use it in GitHub Desktop.
Save Atticuss/c6995d9350a16b7ed36efba504cbefe1 to your computer and use it in GitHub Desktop.
Read in a file and pipe it through a virtual keyboard -- uses the pynput module
import time, string, sys
from pynput.keyboard import Key, Controller
kb = Controller()
shift_keys = {
'<' : ',',
':' : ';',
'>' : '.',
'+' : '=',
'_' : '-',
'{' : '[',
'}' : ']',
'|' : '\\',
'"' : "'",
'~' : '`',
'|' : '\\',
'?' : '/',
'!' : '1',
'@' : '2',
'#' : '3',
'$' : '4',
'%' : '5',
'^' : '6',
'&' : '7',
'*' : '8',
'(' : '9',
')' : '0'
}
def type_file(fname):
with open(fname, 'r') as f:
chars = [c for c in f.read()]
total_chars = float(len(chars))
for i, c in enumerate(chars):
type_character(c)
sys.stdout.write('\r%.4f%%' % (i/total_chars * 100))
sys.stdout.flush()
def type_character(c):
if c == '\t':
kb.type([Key.tab])
elif c == '\n':
kb.type([Key.enter])
elif ord(c) >= 65 and ord(c) <= 90:
with kb.pressed(Key.shift):
kb.type(c.lower())
elif (ord(c) >= 48 and ord(c) <= 57) or (ord(c) >= 97 and ord(c) <= 122):
kb.type(c)
elif c in shift_keys:
with kb.pressed(Key.shift):
kb.press(shift_keys[c])
kb.release(shift_keys[c])
else:
kb.type(c)
if __name__ == '__main__':
time.sleep(5)
target_file = 'powerup/Get-System.ps1'
type_file(target_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment