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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| import pyautogui import pydirectinput import time import os import sys pyautogui.PAUSE = 0
def get_resource_path(relative_path): if hasattr(sys, '_MEIPASS'): return os.path.join(sys._MEIPASS, relative_path) return os.path.join(os.path.abspath("."), relative_path)
def repeat_keys(keys): try: a = time.time() bb = time.time() while a-bb+5000>0: for key in keys: pyautogui.keyDown(key) time.sleep(1) pyautogui.keyUp(key) time.sleep(9) bb = time.time() pyautogui.press('esc') except KeyboardInterrupt: print("Stopped by user")
def identify_picture(a): left, top, width, height = pyautogui.locateOnScreen(get_resource_path(a),confidence=0.9,grayscale=True) center = pyautogui.center((left, top, width, height)) print('开始',center) pydirectinput.moveTo(center[0],center[1]) pydirectinput.click() time.sleep(10)
while True: try: identify_picture('img\sta1.png') except TypeError: try: identify_picture('img\\bac.png') except TypeError: try: identify_picture('img\\img.png') repeat_keys(['w', 'a', 's', 'd']) except TypeError: try: identify_picture('img\\img_1.png') except TypeError: try: identify_picture('img\\img_2.png') except TypeError: try: identify_picture('img\\img_3.png') except TypeError: print('无') time.sleep(2)
|