【发布时间】:2019-08-05 15:44:38
【问题描述】:
我正在为 10fastfingers.com 编写一个自动打字机器人。它有效。
我使用 pytesseract 库来查找文本,然后我使用 pyautogui 按键。 我知道 pyautogui.press 没那么快。
我发现类似 pyautoguide.press 但速度不错。 赞this video
from PIL import Image
import pyautogui
import time
import cv2
import pytesseract
class Cordinates():
textbox = (80, 275)
replayBtn = (800,450)
whereitype = (250,460)
def restartGame():
pyautogui.click(Cordinates.replayBtn)
def main():
restartGame()
time.sleep(0.5)
pyautogui.click(Cordinates.whereitype)
while True:
pyautogui.screenshot('image.png')
img = cv2.imread("image.png")
crop_image = img[320:370, 80:940]
cv2.imshow("cropped", crop_image)
cv2.imwrite('cropped.png',crop_image)
text = pytesseract.image_to_string(crop_image, lang='eng')
for c in text:
print(c)
if c == 'enter':
c=' '
pyautogui.press(c)
if pyautogui.position() == (1, 1):
exit()
pyautogui.press(' ')
main()
【问题讨论】: