What I'm trying to do is? automate a game using coordinates and pywin32.
Expected result:
getting R of RGB colors value of using pyautogui.pixel(489, 209)[0] and check the R value is corresponded to what I am looking for, if it meets requirement perform a mouse click.
Drawback result:
Once the code is run while loop start to work and click event performs until the if statement run into else statement. that resulted unwanted and unnecessary time consuming. is there anyway I can perform the click() method only once inside of this while loop.
import keyboard
import pyautogui
import time
import win32api, win32con
def click(x, y):
win32api.SetCursorPos((x, y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0)
time.sleep(0.1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
while not keyboard.is_pressed('q'):
if pyautogui.pixel(686, 172)[0] != 255:
print("he is not looking at you, click the mouse")
click(680, 694)
else:
print("he is looking at you, click again")
click(680, 694)