By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,247 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,247 IT Pros & Developers. It's quick & easy.

pyGame - Logitech rumble pad input OS X (10.3.9)

P: n/a
kjm
Hi everyone,

I have recently acquired a Logitech Rumble pad to use as an input
device. I have been having trouble getting the event que to respond
that a button or hat arrow has been pressed. This is on a system
running OS 10.3.9.

I have modified/written a small piece of code that initializes the
joystick, and pygame does recognize it. I was wondering if someone has
a small snippet of code to get me going? I have posted the code I'm
using to initialize the joystick, plus it's output below.

Versions are:

Version checklist:

Python version 2.3 (OK)
extra Python info: (#1, Sep 13 2003, 00:49:11) [GCC 3.3 20030304 (Apple
Computer, Inc. build 1495)]
Numeric version 24.0b1 (OK)
PyOpenGL (package "OpenGL") version 2.0.2.01 (OK)
pygame version 1.7.0 (OK)
Python Imaging Library (package "Image") version 1.1.5 (OK)

any help is appreciated.

Cheers,
kjm

[begin code]
-------------------------------------------------
import pygame
import pygame.display
import pygame.joystick
from pygame.locals import *

pygame.display.init()

pygame.joystick.init() #initialize joystick module
pygame.joystick.get_init() #verify initialization (boolean)

joystick_count = pygame.joystick.get_count()#get number of joysticks
print('%d joystick(s) connected' %joystick_count)#print number

joystick_object = pygame.joystick.Joystick(0)
#create an instance of a joystick
#first joystick is [0] in the list
#haven't had much luck with multiple joysticks

joystick_object.get_name()
print joystick_object.get_name()
#grab joystick name - flightstick, gravis...
#can (and is in this case) be done before initialization

joystick_object.init()

joystick_object.get_init()
#verify initialization (maybe cool to do some
#error trapping with this so game doesn't crash

num_axes = joystick_object.get_numaxes()
num_buttons = joystick_object.get_numbuttons()

print 'Joystick has %d axes and %d buttons' %(num_axes,num_buttons)

pygame.event.pump()
#necessary for os to pass joystick events

xaxis = joystick_object.get_axis(0)
yaxis = joystick_object.get_axis(1)
wheel = joystick_object.get_axis(2)
trigger = joystick_object.get_button(0)
top = joystick_object.get_button(1)
#from above, you have number of axes and buttons
#could assign more if your joystick has more

print '%f %f %f %d %d' %(xaxis, yaxis, wheel, trigger, top)
#print values to console for debugging
#analog channels (axes) range -1 to 1
#digital channels (buttons) are 1 or 0


joystick_object.quit()
#destroy objects and clean up
pygame.joystick.quit()

[/code]
------------------------------------------------------------------
[begin output]

[XXXXXXX@viridian 16:10:26]$ python testjoy.py
1 joystick(s) connected
Logitech Cordless RumblePad 2
Joystick has 4 axes and 12 buttons
-1.000000 -1.000000 -1.000000 0 0
[XXXXX@viridian 16:10:32]$

[/output]

Aug 30 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Tuesday 30 August 2005 03:17 pm, kjm wrote:
I have modified/written a small piece of code that initializes the
joystick, and pygame does recognize it. I was wondering if someone has
a small snippet of code to get me going? I have posted the code I'm
using to initialize the joystick, plus it's output below.
First of all, you'd be much better off asking this question on
the pygame mailing list ( py**********@seul.org ).

But ...
pygame.event.pump()
#necessary for os to pass joystick events


You understand, you have to call pygame.event.pump()
ONCE PER EVENT LOOP?

The code you posted doesn't do that. "pump" doesn't
start a separate thread or anything, it just polls the
event queue and runs some pygame code to update state.

You must repeatedly call it to check for events.

Pygame tries to be very straightforward and explicit.
There isn't much hidden "magic" going on (although
movie and sound objects *do* process things in background
threads).

Cheers,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks http://www.anansispaceworks.com

Aug 30 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.