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

Re: [pygame] Re: more on joysticks



Pete Shinners(e)k dio:
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).

ok, this makes much more sense, of course.

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 *".

yes i know this, but for some reason if i do this in the terminal python import pygame print pygame.locals

i get an error unless i do the import pygame.locals maybe something to do with OSX? or maybe i am doing something stupid, this last wouldnt suprise me ...
However with the PyOxide interactive python i can do it with no problems without importing pygame.locals


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.

there is no joystick event handling implemented on it that i could see, only mouse events. The joystick it is initialised but nothing else. It would be nice to have some joystick events there for people to check out when learning.


thanks, now it is much more clear.

--
altern