I am trying to exit a loop by pressing a escape key but my program doesn't work. Is there a way to do that? My code :
import win32api
import win32con
import time
from msvcrt import kbhit,getch
def clickerleft(x,y):
"""Clicks on given position x,y
Input:
x -- Horizontal position in pixels, starts from top-left position
y -- Vertical position in pixels, start from top-left position
"""
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
def fonctionclic():
while True :
clickerleft(1193,757)
time.sleep(0.1)
while True :
key = ord(getch())
if key == 97: #a
fonctionclic()
elif key == 27: #escap
break