Jump to content
  • Advertisement
Sign in to follow this  

pygame: is there a way to get input from xbox controller?

This topic is 1942 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


Yes. Write a python module in C using DirectInput, and use that module in your python program. I don't think there is another way, unless somebody already has done that and is offering their library up for free.

Share this post

Link to post
Share on other sites



i found a small script on the net:




#!/usr/bin/env python

# Written by alex@nyrpnz.com March 14 2012
"Event echoer in Pygame."
import pygame
from pygame.locals import *
def main():
        "Opens a window and prints events to the terminal. Closes on ESC or QUIT."
        screen = pygame.display.set_mode((640, 480))
        clock = pygame.time.Clock()
        joysticks = []
        for i in range(0, pygame.joystick.get_count()):
                print "Detected joystick '",joysticks[-1].get_name(),"'"
        while 1:
                for event in pygame.event.get():
                        if event.type == QUIT:
                                print "Received event 'Quit', exiting."
                        elif event.type == KEYDOWN and event.key == K_ESCAPE:
                                print "Escape key pressed, exiting."
                        elif event.type == KEYDOWN:
                                print "Keydown,",event.key
                        elif event.type == KEYUP:
                                print "Keyup,",event.key
                        elif event.type == MOUSEMOTION:
                                print "Mouse movement detected."
                        elif event.type == MOUSEBUTTONDOWN:
                                print "Mouse button",event.button,"down at",pygame.mouse.get_pos()
                        elif event.type == MOUSEBUTTONUP:
                                print "Mouse button",event.button,"up at",pygame.mouse.get_pos()
                        elif event.type == JOYAXISMOTION:
                                print "Joystick '",joysticks[event.joy].get_name(),"' axis",event.axis,"motion."
                                if event.axis == 4:
                                        print ' axis 4', event.value
                                elif event.axis == 3:
                                        print ' axis 3', event.value
                        elif event.type == JOYBUTTONDOWN:
                                print ("Joystick '",joysticks[event.joy].get_name(),
                                    "' button",event.button,"down.")
                        elif event.type == JOYBUTTONUP:
                                print "Joystick '",joysticks[event.joy].get_name(),"' button",event.button,"up."
                        elif event.type == JOYHATMOTION:
                                print "Joystick '",joysticks[event.joy].get_name(),"' hat",event.hat," moved."
if __name__ == "__main__":
Edited by nickme

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!