我试图让这段代码在屏幕上找到图像(1920x1080),但什么都不做,直到它看不到图像,然后运行一个基本的打印,说“无图像”
代码:
import time
import keyboard
import pyautogui
import win32api
import win32con
import schedule
def click():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
time.sleep(0.1)
while not keyboard.is_pressed('q'):
start = pyautogui.locateCenterOnScreen('7.png', region=(0, 0, 1920, 1080), grayscale=True, confidence=0.70)
if start is not None:
pyautogui.moveTo(start) # Moves the mouse to the coordinates of the image
click()
else:
print("No image")
schedule.every(1).seconds.do(click)
while True:
schedule.run_pending()
time.sleep(1)
没关系,我找到了解决方案..
try:
location = pyautogui.locateOnScreen('7.png')
print('image found')
except pyautogui.ImageNotFoundException:
print('ImageNotFoundException: image not found')