import win32api,win32gui,win32confrom pynput.keyboard import Listener def clickLeftCur(): win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN|win32con.MOUSEEVENTF_LEFTUP, 0, 0)def press(key): if(key.char=='2'): n=0 while n<500: clickLeftCur() n+=1with Listener(on_press = press) as listener: listener.join()