我正在尝试为我玩的游戏创建一个宏。我想使用pyautogui找到一个具有置信度=(0.2)
的图像,然后将鼠标移动到其位置并单击。我不知道接下来该怎么办。它将找到图像并打印,但当我尝试添加pyautogui时。单击('forgedspirit.png')
我得到一个错误:无法解压缩不可编辑的非类型对象
。
def new_method():
if pyautogui.locateOnScreen('forgespirit.png', confidence=(0.2)) != None:
print("I can see it.")
pyautogui.click('forgespirit.png')
time.sleep(0.5)
else:
print("image not found")
time.sleep(0.5)
new_method()
您应该告诉pyautogui单击图像的坐标,而不是让它单击图像。试试这个:
try:
pos = pyautogui.locateOnScreen('forgespirit.png', confidence=(0.2))
if pos != None:
print("I can see it.")
pyautogui.click(pos[0], pos[1])
time.sleep(0.5)
else:
print("image not found")
time.sleep(0.5)
except:
print("image not found")