[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] joystick example
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] joystick example
- From: altern <altern2@xxxxxxxxx>
- Date: Wed, 14 Sep 2005 10:18:38 +0200
- Delivered-to: email@example.com
- Delivered-to: firstname.lastname@example.org
- Delivered-to: email@example.com
- Delivery-date: Wed, 14 Sep 2005 04:18:15 -0400
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:user-agent:x-accept-language:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding; b=lI8S1d7wfojQTEY+DayyNCmZBDpogH8XsvUxIJZSz3OqiAke9PaDjyNfcS4zpgIC2o4KlJyHTkftMbPB71IamLtiiT/5lpMRuDZjeDAxa2gdR9W3F2eSoYsLAfgIvHZI42m6scUVLK4ebeeJtM3ehxTCxFlkMj4/64yk/eMurbc=
- In-reply-to: <1126624751.8256.20.camel@petebox>
- References: <4326B937.firstname.lastname@example.org> <1126624751.8256.20.camel@petebox>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
- User-agent: Mozilla Thunderbird 1.0.6 (Macintosh/20050716)
I put together this code below from different sources. But I am only
getting JOYAXISMOTION events, i mean the conditional never branches into
joybuttonup or joybuttondown etc...
I am using two USB gamapads like the ones from playstation. My system is
from pygame import locals
pygame.joystick.init() # main joystick device system
j = pygame.joystick.Joystick(0) # create a joystick instance
j.init() # init instance
print 'Enabled joystick: ' + j.get_name()
print 'no joystick found.'
for e in pygame.event.get(): # iterate over event stack
print 'event : ' + str(e.type)
if e.type == pygame.locals.JOYAXISMOTION: # 7
x , y = j.get_axis(0), j.get_axis(1)
print 'x and y : ' + str(x) +' , '+ str(y)
elif e.type == pygame.locals.JOYBALLMOTION: # 8
print 'ball motion'
elif e.type == pygame.locals.JOYHATMOTION: # 9
print 'hat motion'
elif e.type == pygame.locals.JOYBUTTONDOWN: # 10
print 'button down'
elif e.type == pygame.locals.JOYBUTTONUP: # 11
print 'button up'
Pete Shinners(e)k dio:
On Tue, 2005-09-13 at 13:34 +0200, altern wrote:
has anyone have a good example or tutorial where joystick funcitonality
is explained in detail? I havent used joysticks so far so the
terminology is a bit weird for me
The "alien" example that comes with pygame supports a joystick. (hmm, I
think, it's been awhile since I looked). You can also play with the
"eventlist" example which will report all events from the joystick.
A basic joystick generally has two axis and a few buttons. Axis 0 is
always left/right and axis 1 is up/down. There are also advanced flight
simulator joysticks which have a lot more gadgets on them. First, the
big joysticks will have more axis on them. Things like twist, throttle
control, and even foot rudders will be counted as additional axis. The
"hats" are miniature joysticks on the joystick, They are usually
controlled by the thumb. Lastly, there are also "balls" on the joystick
which are like little trackballs on the joystick. These work sort of
like mice, but controlled with one finger. Also note that little
gamepads will still use the first two axis for the direction pad, even
though it's not really an analog axis. This is good since it keeps the
analog joysticks and gamepads somewhat similar for software.