The while loop returns true even when I have let go of the left mouse button which would make pressed = false. I don't know how to break out of the loop to update the pressed value.
from pynput import keyboard
from pynput import mouse
from pynput.mouse import Button, Controller
control = Controller()
def on_click(x, y, button, pressed):
if button == mouse.Button.left:
while pressed == True:
print(pressed)
with mouse.Listener(
on_click=on_click) as listener:
listener.join()
Is there any way to update the loop so it knows when pressed = false.
If you really have to run some loop then you have to do it in separted
threadbecause if you run it inon_clickthen you blocklistenerand it can't run anotheron_clickon_clickshould start loop inthreadand use global variable to control when it should stop.