title: How to make my kill switch more effective?
body: <p>I made an auto clicker with a kill switch. Once you press &quot;s&quot; the program stops. The only problem is that you have to hold the &quot;s&quot; key until the Auto_Click function finishes. In the code, I set the function to run for 0.5 seconds.</p>
  <p>How would I make my kill switch more effective? I want the program to stop the moment you hit the key.</p>
  <pre><code>#! /usr/bin/python
  
  import pyautogui
  import time 
  import keyboard
  
  # The Switch
  on_off = True 
  
  print(&quot;Auto Clicker Started&quot;)
  
  # This function does the clicking
  def Auto_Click():
      width, height = pyautogui.position()
      pyautogui.click(width, height)
      time.sleep(0.5)
  
  # Checks if you hit the kill button. If you did not hit the kill button, run the Auto_Click function. 
  while on_off == True:
  
    if keyboard.is_pressed('s') == True:
          on_off = False
          print(&quot;Auto Clicker Killed&quot;)
          
    Auto_Click()      
  </code></pre>