I am using a infinite loop constantly scanning a X,Y place at my screen waiting for the color to change (I need it to be as fast as possible, as soon as the color changes), then send a key press but this is making my computer lag a lot, any tips on how to improve my code? I already tried using more time.sleep
s but doesn't helped that much
import time
import pyautogui
from PIL import Image, ImageGrab
x = 100
y = 100
color = ImageGrab.grab().getpixel((x, y))
repeat = True
while repeat:
time.sleep(0.05)
newcolor = ImageGrab.grab().getpixel((x, y))
if newcolor != color:
pyautogui.press('b')
time.sleep(0.1)