这是我的代码:
from pyautogui import *
import pyautogui
import time
import keyboard
import random
import win32api, win32con
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
time.sleep(random.uniform(0.04, 0.1))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
def writeToChat(input):
for i in range(len(input)):
letter = input[i]
keyboard.press_and_release(str(letter))
time.sleep(0.1)
commandDebounce = False
currentDebounceTime = 0
commandDebounceTime = 15
time.sleep(1)
letters = ['a.png', 'b.png', 'c.png', 'd.png', 'e.png', 'f.png', 'g.png', 'h.png', 'i.png', 'j.png', 'k.png', 'l.png', 'm.png','n.png', 'o.png', 'p.png', 'q.png', 'r.png', 's.png', 't.png', 'u.png', 'v.png', 'w.png', 'x.png', 'y.png', 'z.png']
print('start of script')
haystack = None
while keyboard.is_pressed('q') == False:
msg = ''
if pyautogui.locateOnScreen('command_text.input.png',confidence=0.8):
print('Found command')
x,y = pyautogui.locateCenterOnScreen('command_text.input.png',confidence=0.8)
print(x, y)
win32api.SetCursorPos((x, y))
haystack = pyautogui.screenshot(region=(x + 88, y - 20, 100, 50), imageFilename='screenShot.png')
for i in range(len(letters)):
if pyautogui.locateOnScreen(letters[i], haystack):
print(msg)
break
# if pyautogui.locateOnScreen('command_text.input.png',confidence=0.45):
print('End of script')
这是错误:
> Traceback (most recent call last): File
> "C:\Users\HP\Documents\Bots\CoC\test.py", line 44, in <module>
> if pyautogui.locateOnScreen(letters[i], haystack): File "C:\Users\HP\AppData\Local\Programs\Python\Python310\lib\site-packages\pyautogui\__init__.py",
> line 175, in wrapper
> return wrappedFunction(*args, **kwargs) File "C:\Users\HP\AppData\Local\Programs\Python\Python310\lib\site-packages\pyautogui\__init__.py",
> line 213, in locateOnScreen
> return pyscreeze.locateOnScreen(*args, **kwargs) File "C:\Users\HP\AppData\Local\Programs\Python\Python310\lib\site-packages\pyscreeze\__init__.py",
> line 381, in locateOnScreen
> if retVal or time.time() - start > minSearchTime: TypeError: '>' not supported between instances of 'float' and 'Image
它应该在看到命令后拍摄屏幕截图并检测它后面的字母。我得到的只是那个错误。