Reputation: 1
Here is my code:
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
I want to make sure that my code cannot click the same place twice and instead remember where it has clicked and not click the same place a second time. How can I do that?
Upvotes: 0
Views: 147
Reputation: 7055
Because all of your coordinate pairs can be expressed as a tuple, you can use a set
to keep track of where has been clicked, and only click somewhere that hasn't already been clicked:
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)
...
Upvotes: 1