So I have a script called clicker.py
. All this program does is click one one spot forever. My problem is, how can I kill this program? I can't switch to the command prompt window to press CTRL + C
on my keyboard to make the script get a KeyboardInterrupt
because clicker.py
will just click out of the command prompt window.
How can I make it so, if I press the esc
key on my keyboard, it breaks out of the loop? It needs to detect basically all keystrokes in the background.
As soon as I run the script. It spam clicks the blue area (in the picture). As soon as it clicks that blue area, the command prompt window is no longer on top. Now I can't access the command prompt window because if I try to switch the window, it'll click in the blue area and the photoshop window will be on top again.
clicker.py
import pyautogui
print("Welcome")
while(1):
pyautogui.click(x=100, y=100, button="left")
# If esc is pressed break out of loop (You don't need to press esc in the command window. Just press esc)
print("Bye! See you next time")
I tried this (but it didn't work because you have to press esc
while you have the command prompt window up
import pyautogui
import keyboard
print("Welcome")
while(1):
pyautogui.click(x=100, y=100, button="left")
if (keyboard.is_pressed('q'):
print("exiting loop")
break
print("Bye! See you next time")