Joystick

From XPUB & Lens-Based wiki
Revision as of 00:17, 28 July 2009 by Michael Murtaugh (talk | contribs) (New page: A simple pygame project to view joystick / gamepad data... <source lang="python"> import sys, pygame pygame.init() pygame.joystick.init() if pygame.joystick.get_count() > 0: print "cr...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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()