I'm trying to write a script which will automate the boring stuff at work. To do so, I'am using "pyautogui" and most of the script is done. The OS is windows btw.
My problem is, I'm currently using time.sleep() commands for the script to work between every steps of process but it would be better to detect RGB value of a certain pixel.
What I have done for now is like this;
pyautogui.click(req_management_find[0],req_management_find[1])
time.sleep(2)
pyautogui.click(req_management_print[0],req_management_print[1])
while True:
time.sleep(0.5)
pix=pyautogui.pixel(1348,131)
if pix[1] == 27 and pix[2] == 161 and pix[3] == 226:
break
else:
time.sleep(0.5)
pyautogui.click(req_print_close[0],req_print_close[1])
This just waits forever instead of breaking out of the while loop. I have read the pixel's RGB value by using pyautogui.displayMousePosition()
. It is (255, 255, 255) normally. After some uncertain time the program I'm trying to script gives a pop-up which changes the pixel's RGB from (255, 255, 255) to (27, 161, 226).
Why doesn't my code detect this change?
The indices start at 0, so it's:
if pix[0] == 27 and pix[1] == 161 and pix[2] == 226:
or you could make it more explicit by using:
if pix.red == 27 and pix.green == 161 and pix.blue == 226:
And of course, as suggested by @Aditya Santoso:
if pix == (27, 161, 226):