title: Pynput- Running a while loop in both a keyboard and mouse listener
body: <p>The point of the program is to detect when both the ctrl key and left mouse is held down. When I run it the <code>detect</code> function is still run even after I have released the ctrl key. It seems that <code>on_press</code> does not update the ctrl key's boolean value and <code>detect</code> will still run with only holding down left mouse button.</p>
  <pre><code>import threading
  from pynput import mouse
  from pynput import keyboard
  
  mouse_running = False
  keyboard_running = False
  
  coordList = [(2, 3), (1, 7), (4, 8)]
  
  def detected():
      while keyboard_running and mouse_running:
          for i in coordList:
              move_point = coordList[i]
              #move_point is now a tuple from the coordList. ex: (2, 3)
              pointer.move(move_point[0], move_point[1])
  
  
  def on_click(x, y, button, pressed):
      global mouse_running
      if button == mouse.Button.left:
          if pressed:
              if not mouse_running:
                  mouse_running = True
                  threading.Thread(target=detected).start()
          else:
              mouse_running = False
  
  
  def on_press(key):
      global keyboard_running
      if key == keyboard.Key.ctrl_l:
          if not keyboard_running:
              keyboard_running = True
              threading.Thread(target=detected).start()
      else:
          keyboard_running = False
  
  
  Mouse_Listener = mouse.Listener(on_click=on_click)
  Keyboard_Listener = keyboard.Listener(on_press=on_press)
  
  Mouse_Listener.start()
  Keyboard_Listener.start()
  Keyboard_Listener.join()
  Mouse_Listener.join()
  </code></pre>
  <p>The lmb will continue to run <code>detect</code> after one press of the ctrl key. Is there any way I can make <code>detect</code> run if both lmb and ctrl are held down.</p>
  <p>Here's an annotated console result of the program. The left is the value of <code>keyboard_running</code> and the right is the value of <code>mouse_running</code>.</p>
  <pre><code>#ctrl pressed and released, left mouse pressed once
  True True
  False True
  False True
  False True
  False True
  False True
  False True
  #False True continues about 30 times.
  </code></pre>
  <p>Much appreciation</p>