Example #1
0
		else:
			print "%s released" % (jdev.event_number)
	elif jdev.event_type & 0x02:
		# joystick moved			#define JS_EVENT_AXIS	0x02
		print("axis moved")
		print"number: " + str(jdev.event_number) + ", value: " + str(jdev.event_value)
	else:
		print("unknown event: %s" % jdev.event_type)

# list available devices
print('available devices: ')
for fn in os.listdir('/dev/input'):
	if fn.startswith('js'):
		path = '/dev/input/' + fn
		jdev = Joystick(path)
		jdev.initialize()
		if jdev.deviceName == 'Generic X-Box pad':
			print('correct device: %s' % jdev.deviceName)
			break
		else:
			print('incorrect device: %s' %jdev.deviceName)
			jdev.close()

count = 0
while count < 30:
	jdev.read_event()
	if jdev.newData:
		processEvent(jdev);
		count = count + 1

jdev.close()