[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] joystick example



hi again

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 OSX 10.3.9


any tips?

######
import pygame
from pygame import locals

pygame.init()

pygame.joystick.init() # main joystick device system

try:
	j = pygame.joystick.Joystick(0) # create a joystick instance
	j.init() # init instance
	print 'Enabled joystick: ' + j.get_name()
except pygame.error:
	print 'no joystick found.'

while 1:
	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.

http://www.amazon.com/gp/product/images/B00030GSJY/ref=dp_product-image-only_0/102-0809929-0151342





--
altern