moses-palmer / pynput

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

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

Open tscizzlebg opened 3 years ago

tscizzlebg commented 3 years ago

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 commented 3 years ago

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.

ezamorag commented 6 months ago

Is there a solution to this issue or alternatives to detect scrolls from track pads?