Mimicking a keyboard

Using the pynput module, I tried to make a 'macro' by just making the computer type in stuff. Unlike printing stuff or putting things into a file, this will allow me to 'type' at a very fast speed, and to be honest I was just messing around with it. First thing I did was make it type out a given string, then I moved on to typing out a given file. I tested with stuff like game config files, and find out that if the file is too long, it'll have hiccups near the end of the file. And I don't mean like small mistakes, it just doesn't do it properly. I tested it twice to see if the same mistakes occur, and they were different:

Last line of test1:

nb   tl   .gitttonwii AAAccls

Last line of test2:

sAA


I went and found some ASCII art and tried to paste it into Discord and Minecraft, but both were unfruitful. It would've worked for discord, even though it had message sending limits, if I just slowed the sending by like half a second it was fine, except for the fact that Discord tries to "clean up" a message by getting rid of unnecessary whitespaces. That's fine for normal messages, but not for ASCII art. Minecraft had a different problem, where it didn't even accept simulated inputs, and only accepted inputs from something called DirectInput. It worked fine on just normal notepad though. 

def sentence(string):
keyboard.type(string)


def bee():
sentence("According to all known laws of aviation,")
sentence("there is no way a bee should be able to fly.")
sentence("Its wings are too small to get its fat little body off the ground.")
sentence("The bee, of course, flies anyway")
sentence("because bees don't care what humans think is impossible.")


def file_reading(file_name):
fo = open(file_name, "r+")
lines = []
while True:
line = fo.readline()
line = line[0:len(line)-1]
lines.append(line)
if line == "":
break
for x in lines:
keyboard.press(Key.enter)
time.sleep(1)
keyboard.press('`')
keyboard.release('`')
sentence(x)
keyboard.press('`')
keyboard.release('`')
keyboard.press(Key.enter)
time.sleep(0)
keyboard.press(Key.enter)

Comments