1

嘿,我不擅长编码,但我想在游戏中自动执行一项任务,特别是钓鱼。因此,您必须单击一个按钮,另一个按钮会弹出一个白色圆圈。这个圆圈改变它的大小,当它的按钮大小时,圆圈改变它的颜色,你必须点击按钮才能钓到鱼。因此我搜索了第一个按钮(钓鱼孔),然后点击了它的位置。然后我查看第二个按钮周围的特定像素,它的颜色从白色变为淡红色?如果颜色发生变化,我想单击按钮。除了最后一步之外,一切正常,如果我使用 ,它会移动到那里pyautogui.click(x,y),但它不会点击。有什么办法让它工作(记住我不是一个有经验的程序员)?我试过pyautogui.click(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()
4

1 回答 1

1

尝试制作这样的功能,而不是使用预先构建的功能 -

def click(button):
    pyautogui.mouseDown(button=button)
    pyautogui.mouseUp(button=button)

当我遇到同样的问题时,它对我有用

于 2020-07-31T10:16:08.323 回答