Skip to content

Instantly share code, notes, and snippets.

@NYPDK
Last active November 6, 2020 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NYPDK/2c288d109de467a28386c094cd7913fc to your computer and use it in GitHub Desktop.
Save NYPDK/2c288d109de467a28386c094cd7913fc to your computer and use it in GitHub Desktop.
This is a TypeRacer cheat made in python that uses OCR. Only tested on windows! You will need to install the modules that are being used. You also need to install tesseract. https://tesseract-ocr.github.io/tessdoc/4.0-with-LSTM.html#400-alpha-for-windows Good Luck... Here is a n example video: https://youtu.be/9kue8GAde-c
import pytesseract, cv2, keyboard, time, pyautogui
from pynput.mouse import Listener
# Make sure to download Tesseract and set path to the executable!
pytesseract.pytesseract.tesseract_cmd = (r'D:\\HDD Program Files\\Tesseract\\tesseract.exe')
usr_set_delay = input('Enter a delay value (Example: 0.01): ')
delay = usr_set_delay
pyautogui.PAUSE = 0
print('Starting from the top right, left/right click and drag to select the region to read from')
print('Then quickly click into the text box')
print('To stop the bot, hold left shift for a few seconds. (IMPORTANT!)')
def on_click(x, y, button, pressed):
print(x, y)
if pressed == True:
on_click.rx = x
on_click.ry = y
else:
on_click.rx2 = x
on_click.ry2 = y
listener.stop()
def main():
time.sleep(3)
while keyboard.is_pressed('left shift') == False:
ss = pyautogui.screenshot(region=(on_click.rx, on_click.ry, abs(on_click.rx - on_click.rx2), abs(on_click.ry - on_click.ry2)))
ss.save(r"text.png")
img = cv2.imread('text.png', cv2.IMREAD_GRAYSCALE)
text = pytesseract.image_to_string(img)
with open("words.txt", "w") as file:
file.write(text)
with open('words.txt', 'r') as file:
filedata = file.read()
filedata = filedata.replace('|', 'I')
filedata = filedata.replace('\\', 'I')
with open('words.txt', 'w') as file:
file.write(filedata)
with open('words.txt', 'r') as file:
for line in file.readlines():
pyautogui.write(line, interval=delay)
# Uncomment if being used in typeracer
pyautogui.keyDown('ctrl')
pyautogui.press('backspace', presses=5)
pyautogui.keyUp('ctrl')
time.sleep(0)
with Listener(on_click = on_click) as listener:
listener.join()
main()
print('Program stopped!')
time.sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment