Bots Python AutoGUI未单击
嘿,我很不擅长编码,但我想在游戏中自动化一项任务,特别是钓鱼。因此,您必须单击一个按钮,另一个按钮弹出,周围有一个白色圆圈。这个圆圈的大小不同,当它的大小与按钮的大小相同时,圆圈的颜色也会改变,你必须点击按钮才能钓到鱼。因此,我搜索了第一个按钮(钓鱼孔),并点击了它的位置。然后我看第二个按钮周围的一个特定像素,它将颜色从白色变为淡红色?。如果颜色改变,我想点击按钮。除了这最后一步,一切都正常。如果我使用Bots Python AutoGUI未单击,bots,pyautogui,Bots,Pyautogui,嘿,我很不擅长编码,但我想在游戏中自动化一项任务,特别是钓鱼。因此,您必须单击一个按钮,另一个按钮弹出,周围有一个白色圆圈。这个圆圈的大小不同,当它的大小与按钮的大小相同时,圆圈的颜色也会改变,你必须点击按钮才能钓到鱼。因此,我搜索了第一个按钮(钓鱼孔),并点击了它的位置。然后我看第二个按钮周围的一个特定像素,它将颜色从白色变为淡红色?。如果颜色改变,我想点击按钮。除了这最后一步,一切都正常。如果我使用pyautogui,它会移动到那里。单击(x,y),但它不会单击。有没有办法让它工作(记住我不
pyautogui,它会移动到那里。单击(x,y)
,但它不会单击。有没有办法让它工作(记住我不是一个有经验的程序员)?。我尝试了pyautogui。单击(x,y)
,多次单击,以此类推。多谢各位
import pyautogui as pa
import time
counter = 0
def main():
global counter
# Countdown to open the game
for i in reversed(range(0,5)):
print(i)
time.sleep(1)
# Finding the fishing hole using a prior screenshot
fishing_hole_location = pa.locateOnScreen("fishing_hole.png",confidence = 0.5)
# Getting the center of the hole
fishing_hole_center = pa.center(fishing_hole_location)
# Clicking the hole
pa.click(fishing_hole_center[0], fishing_hole_center[1])
time.sleep(3)
# Locating the second button (even though it appears in the middle of the screen)
fishing_button_location = pa.locateOnScreen("fishing_button.png",confidence = 0.5)
# Finding the buttons center
fishing_button_center = pa.center(fishing_button_location)
while True:
# Looking at the pixel at the edge of the button
pix = pa.pixel(int(fishing_button_center[0]+24), int(fishing_button_center[1]))
# If the pixel doesn´t have its usual colour 5 times in a row, I want to click the button
if pix != (75,99,118):
counter+= 1
if counter >= 5:
pa.moveTo(fishing_button_center[0], fishing_button_center[1])
time.sleep(2)
pa.click()
break
else:
counter = 0
time.sleep(0.1)
main()
尝试创建这样的函数,而不是使用预先构建的函数-
def click(button):
pyautogui.mouseDown(button=button)
pyautogui.mouseUp(button=button)
当我遇到同样的问题时,它对我起了作用