moses-palmer / pynput

Sends virtual input commands
GNU Lesser General Public License v3.0
1.77k stars 245 forks source link

Middle button of a mouse cannot be released #474

Closed gh0styxx closed 2 years ago

gh0styxx commented 2 years ago

Description If I want to perform an action while clicking the middle button on my mouse (scroll button, but I click it, not scroll) the action is performed once. When I release the button, the action is performed once again, because when I release the middle button it is known as pressing. I have the same issue with using another buttons on my mouse, like Button.left or Button.right. If I try to perform the same function using a key on the keyboard, the pressing and releasing the button works like it should, the action is performed only once.

Platform and pynput version I use MacOS 12.3 Monterey and pynput 1.7.6

To Reproduce

def on_click(x, y, button, pressed):
    btn = button.name
    if (btn == 'middle'):
        my_function()

mouse_listener = MouseListener(on_click=on_click)
mouse_listener.start()
mouse_listener.join()

If physically click middle button once and release it, the code under "my_function" will perform twice.

moses-palmer commented 2 years ago

Thank you for your report.

Have you tried calling my_function only when pressed is True? The on_click callback will be triggered when a button is pressed as well as released.

I do not think this is caused by a bug in this library, so I will close this issue. If you think otherwise, please reopen.

gh0styxx commented 2 years ago

Thank you, I missed this variable. it helps to solve my problem. Thanks!