Moein Arabi
Moein Arabi

Reputation: 111

How can I understand when the mouse is pressing?

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')

Upvotes: 1

Views: 58

Answers (1)

smolGeat
smolGeat

Reputation: 11

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()

Upvotes: 1

Related Questions