How to know or track something change on screen

Have you ever wanted to have a tool or program to automatically take screenshots at regular interval and compare them? With just a few lines of codes, Python can help!

import pyautogui
import time
import winsound 

value = True 
while (value): 	#infinite loop	
	img1 = pyautogui.screenshot(region=(0,0, 300, 400)) #take 1st screenshot
	time.sleep(30) #wait 30 seconds
	img2 = pyautogui.screenshot(region=(0,0, 300, 400)) #take 2nd screenshot
	if img1 != img2: #compare and if 1st and 2nd screenshot are different
		winsound.Beep(440, 1000) #play sound
		pyautogui.alert("Something changed") #alert box

For more info on PyAutoGUI screenshot function, check out https://pyautogui.readthedocs.io/en/latest/screenshot.html

You might want to consider adding keystrokes at regular interval, then check out  https://pyautogui.readthedocs.io/en/latest/keyboard.html

Comments