Sep-10-2018, 03:02 PM
With buran's blessed directives I could easily solve the last question by myself. Sorry to have bothered others.
Coming from C, C# and new to Python, I totally ignored (forgot) the Python's Global declaration, and could not make a global variable to run inside function.
Once I recognized this, it was easy to solve.
In the code snippet, the while loop will normally (auto = 1) run by time, but if set auto = 0 it will run by mouse clicks.
Coming from C, C# and new to Python, I totally ignored (forgot) the Python's Global declaration, and could not make a global variable to run inside function.
Once I recognized this, it was easy to solve.
In the code snippet, the while loop will normally (auto = 1) run by time, but if set auto = 0 it will run by mouse clicks.
#!/usr/bin/env python from pynput import mouse clicked = False def foo(): counter = 0 auto = 0 global clicked while counter < 10: if auto == 0: runTime = 0 # runTime = 0 will hold the next while loop waiting for mouse click if runTime > counter or clicked: print(counter,"clicked") clicked = False counter += 1 runTime = counter #Time progress (example) def on_click(x, y, button, pressed): global clicked if pressed: clicked = pressed listener = mouse.Listener(on_click=on_click) listener.start() if __name__ == '__main__': foo()