title: My script in python is running slow i think it is caused by a listener
body: <p>I created a python script that runs two functions for a video game and they are working well but to activate them I want to do it with some keys so I create a keyboard listener and it recognizes the keys well but the problem is that despite having returns if it is not the Trigger key it starts to slow the whole keyboard when I play any key</p>
  <p>Here I leave the whole script, the listener is at the end, if someone finds something that may be the cause please tell me, even if it is only a recommendation so that this may not happen</p>
  <pre><code>from pynput.mouse import Button, Controller
  from pynput.keyboard import Listener
  import threading
  import time
  import keyboard
  
  controller = Controller()
  break_cobblestone_time = 1
  spawn_cobblestone_time = 0.35
  button_break = Button.left
  button_use = Button.right
  
  class AutomationThreads(threading.Thread):
  
      def __init__(self, button_break, button_use, break_cobblestone_time, spawn_cobblestone_time):
          super(AutomationThreads, self).__init__()
          self.button_break = button_break
          self.button_use = button_use
          self.running_mining = False
          self.running_bridge = False
          self.break_cobblestone_time = break_cobblestone_time
          self.spawn_cobblestone_time = spawn_cobblestone_time
          self.count = 1
  
      def start_automation(self, func):
          if func == 'miner':
              self.running_mining = True
          elif func == 'bridgeBuilder':
              self.running_bridge = True
              controller.press(self.button_use)
  
      def stop_automation(self, func):
          if func == 'miner':
              self.running_mining = False
          elif func == 'bridgeBuilder':
              self.running_bridge = False
              controller.release(self.button_use)
  
      def run(self):
          while True:
              
              while self.running_bridge:
                  keyboard.press('s')
                  #keyboard.press('d')
                  time.sleep(1)
                  
              while self.running_mining:
                  controller.press(self.button_break)
                  time.sleep(self.break_cobblestone_time)
                  keyboard.press(str(self.count))
                  time.sleep(self.spawn_cobblestone_time)
                  self.count += 1
                  if self.count == 10:
                      self.count = 1
  
  automation_thread = AutomationThreads(button_break, button_use, break_cobblestone_time, spawn_cobblestone_time)
  automation_thread.start()
      
  def on_press(key):
      if hasattr(key, 'vk') == False:
          return
      if key.vk != 96 and key.vk != 97 and key.vk != 98:
          return
      print('awd')
      #mining start stop
      if 97 == key.vk:
          if automation_thread.running_mining:
              automation_thread.stop_automation('miner')
          else:
              automation_thread.start_automation('miner')
  
      #bridge builder start stop
      elif 98 == key.vk:
          if automation_thread.running_bridge:
              automation_thread.stop_automation('bridgeBuilder')
          else:
              automation_thread.start_automation('bridgeBuilder')
  
      #stop everything
      elif 96 == key.vk:
          if automation_thread.running_bridge:
              automation_thread.stop_automation('bridgeBuilder')
          if automation_thread.running_mining:
              automation_thread.stop_automation('miner')
  
  with Listener(on_press=on_press) as listener:
      listener.join()
  
  </code></pre>