From e8973545d221d373fe1a3a1115b4eac9e41c4a98 Mon Sep 17 00:00:00 2001 From: Jerry Date: Wed, 6 Oct 2021 21:14:43 +0800 Subject: [PATCH] update --- lumberjackBot.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lumberjackBot.py b/lumberjackBot.py index 37f8e56..ec585c7 100644 --- a/lumberjackBot.py +++ b/lumberjackBot.py @@ -1,23 +1,28 @@ import pyautogui import time from PIL import ImageGrab +import threading # monkey patch pyautogui.pyscreeze.ImageGrab = ImageGrab pyautogui.pyscreeze.screenshot = pyautogui.pyscreeze._screenshot_win32 +def pyautogui_typewrite(btn, sleepintv=0.050*2, typeintv=0.030): + threading.Thread(target=pyautogui.typewrite, args=[btn, typeintv]).start() + time.sleep(sleepintv) + class lumberjackBot(): __author__ = "EnriqueMoran" def __init__(self, x, y): self.branch_width = 60 - self.vertical_branch_distance = 70 + self.vertical_branch_distance = 120 self.to_match = (169, 113, 65) - self.speed = 0.08 + self.speed = 0.078 self.sleep = 0.083 - self.sleep_min = 0.078 - self.sleep_max = 0.090 + self.sleep_min = 0.045*2 + self.sleep_max = 0.050*2 self.xl = x - self.branch_width self.xr = x + self.branch_width @@ -32,18 +37,18 @@ class lumberjackBot(): def play(self): last = [True]*5 - pyautogui.typewrite(['right', 'right'], self.speed) + pyautogui_typewrite(['right', 'right'], self.speed) while True: match_l, match_r = self.get_pixel() if match_l: print('left match') - pyautogui.typewrite(['right', 'right'], self.speed) + pyautogui_typewrite(['right', 'right'], self.speed) elif match_r: print('right match') - pyautogui.typewrite(['left', 'left'], self.speed) + pyautogui_typewrite(['left', 'left'], self.speed) else: if not last[-1]: - pyautogui.typewrite(['right', 'right'], self.speed) + pyautogui_typewrite(['right', 'right'], self.speed) print('!! no match') last.append(match_l or match_r) while len(last) > 5: