[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Re: more on joysticks
On Wed, 2005-09-14 at 17:11 +0200, altern wrote:
> #JOYAXISMOTION joy, axis, value
> #JOYBALLMOTION joy, ball, rel
> #JOYHATMOTION joy, hat, value
> #JOYBUTTONUP joy, button
> #JOYBUTTONDOWN joy, button
Each of these joystick events actually comes with the proper joystick
information. It is better to read the button/axis/hat/ball position from
the actual event, instead of going back to the joystick device.
The joystick devices will not always be in exact sync with the events
that arrive. (This is the same for keyboard and mice events).
Also, there really is no point in referencing "pygame.locals"
indirectly. Everything in pygame.locals is already available in the top
level pygame. The pygame.locals module is just a limited set of pygame
that makes it cleaner to do a "from pygame.locals import *".
You should change your handler code to work like this:
# ...
elif e.type == pygame.locals.JOYBALLMOTION: # 8
print "Moved ball %d on joystick %d by: %s" % (
event.ball, event.joy, event.rel)
elif e.type == pygame.locals.JOYHATMOTION: # 9
print "Moved hat %d on joystick %d to: %s" % (
event.hat, event.joy, event.value)
# ...
You should be getting all this information from the 'eventlist.py'
example that comes with pygame.