【问题标题】:How to make keep track of clicks and not click the same place twice如何跟踪点击而不是两次点击同一个地方
【发布时间】:2021-09-06 00:27:14
【问题描述】:

这是我的代码:

while (1):
    pic = pyautogui.screenshot(region=(200,150,1600,800))
    width, height = pic.size
    for x in range (0,width,1):
    
        for y in range (0,height,1):

            r,g,b = pic.getpixel((x,y))
            if r == 71 and g == 38:

                click(x+200, y+150)
                
                time.sleep(0.5)
               
                if pyautogui.locateOnScreen('kalk.png', grayscale=True,confidence=0.8) != None: 
                    click(1111, 906)
                    time.sleep(0.5)
                    click(1155, 165)
                    time.sleep(0.5)
                    click(1342, 994)
                    pyautogui.press('a')
                    time.sleep(0.5)
                    pyautogui.press('a')
                    time.sleep(0.5)
                    pyautogui.press('a')
                else: 
                    pyautogui.press('ctrl')
                    continue

我想确保我的代码不能两次点击同一个地方,而是记住它点击过的地方,而不是第二次点击同一个地方。我该怎么做?

【问题讨论】:

    标签: python click mouse pyautogui


    【解决方案1】:

    因为您的所有坐标对都可以表示为一个元组,您可以使用set 来跟踪已单击的位置,并且只单击尚未单击的位置:

    while(1):
        pic = pyautogui.screenshot(region=(200,150,1600,800))
        width, height = pic.size
        clicked = set() # Create set
        for x in range (0,width,1):
            for y in range (0,height,1):
                r,g,b = pic.getpixel((x,y))
                if r == 71 and g == 38 and (x, y) not in clicked:  # Check if coordinates already clicked
                    clicked.add((x, y))  # Mark coordinates as clicked
                    click(x+200, y+150)
                    
                    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-29
      • 2022-12-29
      • 1970-01-01
      • 1970-01-01
      • 2015-10-28
      • 1970-01-01
      • 1970-01-01
      • 2015-05-30
      相关资源
      最近更新 更多