#!/usr/bin/env python import pygame, sys,os from pygame.locals import * from pygame.joystick import * class Joy: def __init__(self): pygame.init() self.joy=None self.axes=None self.buttons=None #def __init__ def kill_all(self): pygame.quit() def get_joy_list(self): joy_count=pygame.joystick.get_count() joy_list=[] for item in range(joy_count): tmp_joy=Joystick(item) tmp_joy.init() id=item name=tmp_joy.get_name() axes=tmp_joy.get_numaxes() buttons=tmp_joy.get_numbuttons() joy_info=(id,name,axes,buttons) joy_list.append(joy_info) tmp_joy.quit() return joy_list #def get_joy_list def init_joy(self,id): self.joy=Joystick(id) self.joy.init() self.axes=self.joy.get_numaxes() self.buttons=self.joy.get_numbuttons() #def init_joy def quit_joy(self): self.joy.quit() #def quit_joy def get_all_axes(self): pygame.event.get() axes_list=[] for item in range(self.axes): tmp=self.joy.get_axis(item) axes_list.append(tmp) return axes_list #def get_all_axes def get_axis(self,id): pygame.event.get() return self.joy.get_axis(id) # float [-1..1] #def get_axis def get_all_buttons(self): pygame.event.get() buttons_list=[] for item in range(self.buttons): tmp=self.joy.get_button(item) buttons_list.append(tmp) return buttons_list #def get_all_buttons def get_button(self,id): pygame.event.get() return self.joy.get_button(id) # True or False #def get_axis # class Joy