-
Notifications
You must be signed in to change notification settings - Fork 1
/
typing_test.py
40 lines (35 loc) · 1.32 KB
/
typing_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from PIL import ImageGrab
from ctypes import windll
from win32api import GetSystemMetrics
import pynput
import time
import pytesseract
import sys
myKeyboard = pynput.keyboard.Controller()
myMouse = pynput.mouse.Controller()
screensize = windll.user32.GetSystemMetrics(
0), windll.user32.GetSystemMetrics(1)
# path to tesseract's executable, this is should be the standard path
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
image = None
if (screensize[0] == 1920 and screensize[1] == 1080):
image = ImageGrab.grab(bbox=(588, 375, 1314, 573))
myMouse.position = (950, 430)
elif (screensize[0] == 2560 and screensize[1] == 1440):
image = ImageGrab.grab(bbox=(904, 377, 1634, 575))
myMouse.position = (1275, 478)
else:
print("Sorry, your screen resolution isn't supported.")
sys.exit(1)
if (image is not None):
text = pytesseract.image_to_string(image, lang='eng')
# tesseract sometimes mistakenly reads "I" as "|"
text = text.replace("\n", " ").replace("|", "I")
if (text[len(text) - 1] == " "):
text[len(text) - 1] = "."
# click on text feld to focus it
myMouse.click(pynput.mouse.Button.left, 1)
print(text)
myKeyboard.type(text)
else:
print("There was a problem while taking a screenshot")