1

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.


enter image description here

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")
  • ctrl-c didnt work ?you can always kill it using task manager(ctrl+alt+del) or ps kill – cerofrais Sep 22 '19 at 06:52
  • @VenkataSriHarshaVemuluru Sorry Edited question to make more sense. I can do `CTRL+C`. But imagine running this program. If it clicks in one spot without a delay, how can I possible go to my command prompt window in time and press `CTRL + C`. Its humanly impossilbe for me to switch to my command prompt window and press `CTRL + C` before the script clicks again. If the program clicks, it clicks out of the command prompt window (hence minimizing that window again) –  Sep 22 '19 at 06:53
  • Try take your mouse to the left upper corner! – Prayson W. Daniel Sep 22 '19 at 07:05
  • @PraysonW.Daniel I know `PyAutoGUI` has that fail safe, but how can I do that, when the mouse is being click constantly on one spot (far away from the upper left corner) –  Sep 22 '19 at 07:07
  • Have you tried: https://stackoverflow.com/questions/33182221/how-do-i-have-a-fail-safe-command-in-python – Prayson W. Daniel Sep 22 '19 at 07:08
  • @PraysonW.Daniel Yes I have. Like I said, I can't access the command prompt. So I can't press `CTRL+C`. I added a picture to the question to make it easier to understand –  Sep 22 '19 at 07:13

0 Answers0