1

I want to creat a code in python, while the left button mouse is pressing, print Hello until the button released.

  while(TheLeftMouseButtonPressing):
     print('Hello')
  • it really depends on environment and framework, please check this link and see if it helps. https://stackoverflow.com/questions/9817531/applying-low-level-keyboard-hooks-with-python-and-setwindowshookexa – prhmma Dec 29 '19 at 18:51

1 Answers1

1

Install pynput from pip.
pip install pynput

Then you can listen to mouse clicks like this:

from pynput.mouse import Listener
def on_click(x,y,button,pressed):
    print("Hello")
with Listener(on_click=on_click) as listener:
    listener.join()
julka
  • 1,172
  • 2
  • 13
  • 29
smolGeat
  • 11
  • 3