pynput icon indicating copy to clipboard operation
pynput copied to clipboard

`on_scroll` misses trackpad scroll events, depending on the window the cursor is over

Open tscizzlebg opened this issue 4 years ago • 2 comments

Description When monitoring the mouse (with pynput.mouse.Listener), on_scroll triggers normally when using a USB mouse, but when scrolling up and down with a built-in trackpad, it only triggers sometimes. For example, it triggers ok while the cursor is over a Command Prompt window, a PyCharm window, or a Sublime Text window (whether any of these are the focused window or not). But it does NOT trigger while the cursor is over a Firefox window or a VS Code window.

Platform and pynput version Windows 10, pynput version 1.6.8

To Reproduce Can reproduce with the example "Monitoring the mouse" script from the documentation.

from pynput import mouse


def on_move(x, y):
    print("Pointer moved to {0}".format((x, y)))


def on_click(x, y, button, pressed):
    print("{0} at {1}".format("Pressed" if pressed else "Released", (x, y)))
    if not pressed:
        # Stop listener
        return False


def on_scroll(x, y, dx, dy):
    print("Scrolled {0} at {1}".format("down" if dy < 0 else "up", (x, y)))


# Collect events until released
with mouse.Listener(
    on_move=on_move, on_click=on_click, on_scroll=on_scroll
) as listener:
    listener.join()

# ...or, in a non-blocking fashion:
listener = mouse.Listener(on_move=on_move, on_click=on_click, on_scroll=on_scroll)
listener.start()

tscizzlebg avatar May 06 '21 16:05 tscizzlebg

Note that it does not appear to be about whether the hovered window, or the script, is run with admin permissions. Different combinations of running things as admin yields the same result.

tscizzlebg avatar May 06 '21 16:05 tscizzlebg