Reputation: 93
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?
Upvotes: 9
Views: 12963
Reputation: 31
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
Upvotes: 3
Reputation: 211186
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)
Upvotes: 10