Skip to content

Instantly share code, notes, and snippets.

@tacomonster
Created September 15, 2018 14:29
Show Gist options
  • Save tacomonster/090ae36b534c959af27fab3b333d3f2b to your computer and use it in GitHub Desktop.
Save tacomonster/090ae36b534c959af27fab3b333d3f2b to your computer and use it in GitHub Desktop.
Automating Typing Program
!# /usr/bin/
python /Users/andyrublyov/Desktop/YouTubeVidCode/AutoType/AutoType.py
#1431, 25
#175, 27
"""
Select right side of the screen where text editor is and type one line
After typing on line go back to terminal and ask for user to hit Enter to continue on to the
next line.
"""
import pyautogui
import random
def click_on(x, y):
"""Click on location"""
pyautogui.moveTo(x, y)
pyautogui.click(clicks=1, button='left')
file = r'YOUR/PATH/HERE'
#file = input('What is the File Location? : ')
with open(file.strip(), 'r') as f:
lines = f.readlines()
print("\n***Make sure text editor is open on the right hand side with a blank document!***")
input("Press [ENTER] to Get Started!")
click_on(1431, 25)
for line in lines:
# Simulate somewhat human keystroke speed
t = random.randint(2, 6) / 100
line = line.replace('\n', '')
pyautogui.typewrite(line, interval=t)
pyautogui.press(' ')
click_on(175, 27)
# Press Enter to continue
cont = input('Press Enter to Continue: ')
if cont == '':
pyautogui.moveTo(1431, 25)
pyautogui.click(clicks=1, button='left')
pyautogui.press('return')
pyautogui.hotkey('command', 'left')
"""Used to locate Coordinates on the screen"""
import pyautogui, sys
print('Press Ctrl-C to quit.')
try:
while True:
x, y = pyautogui.position()
positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4)
print(positionStr, end='')
print('\b' * len(positionStr), end='', flush=True)
except KeyboardInterrupt:
print('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment