What module would there be that allows my program to run IF it detects a certain color
for example, if I want my program to type red when #FF0000 pops up on the screen--how can i achieve that. I know how to make python type, i know my conditional statements... i just need to know how to let python grab color.
CodePudding user response:
I think I know what you are looking for
from PIL import ImageGrab
while True:
#gets current image
image = ImageGrab.grab()
#checks which colour a specific spot of your screen has, by coordinates
color = image.getpixel((660, 300))
if color == (255, 0, 0):
print("the color is red")
else:
print("its not red")
CodePudding user response:
Pops up on the screen? The entire screen? A small snippet? A single pixel? It really depends. A basic implementation could be screenshotting on some interval, and parsing each image pixel by pixel to detect the hex code you're looking for.