[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Pygame and Mouse Wheel Events



Hi, this is my first post to the mailing list and I apologize if I screw
something up.

I am building a program that works with repeated mouse wheel events as the user
interface mechanism.  So if I flick the wheel and that's actually 5 clicks, I
want to have some way of identifying that 5 events occurred.

To test this out I'm tracking the event queue by:

for event in pygame.event.get():
   print event


When I do that, I found that I'm only able to get a single mouse wheel event per
event queue "get" cycle.  So for example, if I set the clock to tick only once
per second (slow enough for testing) and click the left button 3 times in that
window, I get three MOUSEBUTTONDOWN events.  If however, I scroll the wheel
rapidly, I only get a single MOUSEBUTTONDOWN event on button 4. If I only get
the event queue once every 5 clock ticks, I can still only get a single event
for the mouse wheel.

Further testing reveals that each event loop is only capable of outputting a
single MOUSEBUTTON down for the mouse wheel in either direction.  The event
that's output appears to be a single click in the net direction.  So if I scroll
down three and up one between .get() calls, I get a single MOUSEBUTTONDOWN 5. 
If I go <down one, up one, down one, up one> I get no events.  If I go <up,
down, up, up, up, up> I get a single MOUSEBUTTONDOWN 4.

There are ways around this limitation.  For example, I can set the frame rate to
be fast (my game isn't complicated) and use a timer to track MOUSEBUTTONDOWN
events that recur within a brief window in time.  There's no perfect fix though.
 Basically, any time you're trying to use mouse wheel events, you run the risk
of losing events and it's kind of limiting your creativity at using the mouse
wheel for non-traditional interface mechanisms.  I wanted to ask whether there's
any practical reason for this behavior, or some well established workaround that
I'm just not aware of.  Is it a limitation of SDL or pygame?