How do I detect Mouse scroll up and down in python using pygame? I have created a way to detect it, but it doesn't give me any information about which way I scrolled the mouse as well as being terrible at detecting mouse scrolls where only 1 in 20 are getting detected.
for event in pygame.event.get():
if event.type == pygame.MOUSEWHEEL:
print("Mouse Scroll Detected.")
Any other ways I can detect mouse scrolls?
The MOUSEWHEEL event object has x and y components (see pygame.event module). These components indicate the direction in which the mouse wheel was rotated (for horizontal and vertical wheel):
for event in pygame.event.get():
if event.type == pygame.MOUSEWHEEL:
print(event.x, event.y)
for event in pygame.event.get():
if event.type == pygame.MOUSEWHEEL:
After this, use event.y == 1 for upward scroll, while event.y == -1 for downward scroll
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With