This is my first time to create a python program to take screenshot every two seconds. The problem is that I don't know how to break the while loop. I wrote while sscount is not zero, keep screenshotting. Then when a user press ESC button, set sscount to 0. This should stop the while loop but I get the warning, "Unused variable 'sscount'" and it doesn't stop the while loop either.
Could anyone help me? Thanks.
import pynput
import pyautogui
import time
from pynput.keyboard import Key, Listener
count = 0
def on_release(key):
if key == Key.esc:
sscount = 0 #this is where the warning comes.
return False
with Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
while sscount != 0:
pyautogui.screenshot('/users/aliha/desktop/screenshot/image'+str(sscount)+'.png')
sscount += 1
time.sleep(2.0)