Search code examples
pythonpygamejoystickvpython

Is it possible to combine VPython and Pygame?


I need to use a joystick for a vpython project, Is it possibe to combine pygame module and vpython to be able to use joystick functions of the pygame module?


Solution

  • Have you tried simply making pygame joystick calls in your vpython event/animation loop? Drop something like this in there, see how it goes (after importing pygame and initing up joysticks).

    from pygame.joystick docs

    for event in pygame.event.get(): # User did something        
        # Possible joystick actions: JOYAXISMOTION JOYBALLMOTION JOYBUTTONDOWN JOYBUTTONUP JOYHATMOTION
        if event.type == pygame.JOYBUTTONDOWN:
            print("Joystick button pressed.")
        if event.type == pygame.JOYBUTTONUP:
            print("Joystick button released.")