Joystick: Difference between revisions
No edit summary |
No edit summary |
||
Line 28: | Line 28: | ||
produces output like: | produces output like: | ||
< | <pre> | ||
<Event(9-JoyHatMotion {'joy': 0, 'hat': 0, 'value': (1, 0)})> | <Event(9-JoyHatMotion {'joy': 0, 'hat': 0, 'value': (1, 0)})> | ||
<Event(11-JoyButtonUp {'joy': 0, 'button': 0})> | <Event(11-JoyButtonUp {'joy': 0, 'button': 0})> | ||
Line 35: | Line 35: | ||
<Event(10-JoyButtonDown {'joy': 0, 'button': 4})> | <Event(10-JoyButtonDown {'joy': 0, 'button': 4})> | ||
<Event(10-JoyButtonDown {'joy': 0, 'button': 5})> | <Event(10-JoyButtonDown {'joy': 0, 'button': 5})> | ||
</ | </pre> |
Revision as of 23:19, 27 July 2009
A simple pygame project to view joystick / gamepad data...
import sys, pygame
pygame.init()
pygame.joystick.init()
if pygame.joystick.get_count() > 0:
print "creating joystick object"
stick = pygame.joystick.Joystick(0)
# print stick
# print dir(stick)
stick.init()
size = width, height = 320, 240
black = 0, 0, 0
screen = pygame.display.set_mode(size)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
running = False
print event
screen.fill(black)
pygame.display.flip()
produces output like:
<Event(9-JoyHatMotion {'joy': 0, 'hat': 0, 'value': (1, 0)})> <Event(11-JoyButtonUp {'joy': 0, 'button': 0})> <Event(9-JoyHatMotion {'joy': 0, 'hat': 0, 'value': (0, 0)})> <Event(7-JoyAxisMotion {'joy': 0, 'value': 0.0, 'axis': 0})> <Event(10-JoyButtonDown {'joy': 0, 'button': 4})> <Event(10-JoyButtonDown {'joy': 0, 'button': 5})>