basic usage of joysticks

Return to Code Snippets

basic usage of joysticks

Postby lvraab » Tue Apr 11, 2006 10:18 am

This is an extremely short script that takes input from a joystick and prints it to the console. Requires Pygame. This is a work in progress. Next up is printing the results inside a Panda window.

http://home.earthlink.net/~lvraab/joystick1.py
lvraab
 
Posts: 96
Joined: Thu May 13, 2004 7:12 am

Postby pleopard » Tue Sep 12, 2006 12:58 pm


Clicky Linky wrote:Page Not Found

We're Sorry! We can't locate the page you requested.

Check the spelling on the Web address (capitalization and punctuation count). Otherwise, go to EarthLink.net, enter a search key word, or check out any of our services below.


Would you be so kind as to correct the link or post the code as text here? I am very interested ... Thx!
User avatar
pleopard
 
Posts: 202
Joined: Tue Apr 25, 2006 1:33 pm

Postby pleopard » Thu Sep 14, 2006 1:51 pm

Found this ... works excellent :

Code: Select all
#Capturing input data from a joystick using Pygame

#Import pygame and init
from pygame import *
init()

#Setup and init joystick
j=joystick.Joystick(0)
j.init()

#Check init status
if j.get_init() == 1: print "Joystick is initialized"

#Get and print joystick ID
print "Joystick ID: ", j.get_id()

#Get and print joystick name
print "Joystick Name: ", j.get_name()

#Get and print number of axes
print "No. of axes: ", j.get_numaxes()

#Get and print number of trackballs
print "No. of trackballs: ", j.get_numballs()

#Get and print number of buttons
print "No. of buttons: ", j.get_numbuttons()

#Get and print number of hat controls
print "No. of hat controls: ", j.get_numhats()

#Setup event information and print data from joystick
while 1:
    for e in event.get():
        if e.type != QUIT:
            print '%s: %s' % (event.event_name(e.type), e.dict)
User avatar
pleopard
 
Posts: 202
Joined: Tue Apr 25, 2006 1:33 pm

Postby Josh Yelon » Tue Oct 31, 2006 4:53 pm

I should mention - the latest version of panda, 1.3.0, sets the registry key that locates the python install directory. This, in turn, makes it easy to install python add-ons like pygame and the like.
Josh Yelon, Teacher, Carnegie Mellon Entertainment Technology Center
Josh Yelon
 
Posts: 1360
Joined: Wed Mar 30, 2005 8:30 pm


Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 0 guests