def __init__(self, UI): self.Joystick = 0 self.deadZone = 15 self.minValue = 0 self.maxValue = 400 foundController = False UI.textwrite( 50, 250, "Looking for controller, press A to choose the controller", 10, 10, 10, 50) UI.update() while not foundController: for i in range(0, 5): Joystick.update() if Joystick.is_connected(i): Joystick.update() if Joystick.is_button_pressed(i, A): foundController = True self.joystick = i UI.shouldQuit() UI.textdelete( 50, 250, "Looking for controller, press A to choose the controller", 50) UI.textwrite(450, 250, "Found " + str(self.joystick), 10, 10, 10, 50) UI.update() time.sleep(2) UI.textdelete(450, 250, "Found " + str(self.joystick), 50)
def readButton(button): """Takes a button value (buttons 1-8) and returns whether or not it is pushed.""" if isConnected(): return j.is_button_pressed(0, button) else: pass
def getButton(button): return Joystick.is_button_pressed(joystick, button)
L_JOYSTICK_CLICK = 9 R_JOYSTICK_CLICK = 10 WIN_BUTTON = 8 #loop to find the correct controller joystick = 0 foundController = False print "looking for controller, press A to chose the controller" while not foundController: for i in range(0, 5): Joystick.update() if Joystick.is_connected(i): Joystick.update() if Joystick.is_button_pressed(i, A): foundController = True joystick = i print "found controller ", i print "buttons: ", Joystick.get_button_count(i) # used inside the class, not necessary to call from outside this class, use the other calls def getAxis(joyStickNumber, axis): size = maxValue - minValue return ((applyDeadZone(Joystick.get_axis_position(joyStickNumber, axis)) / (100.0 - deadZone)) * size) - minValue
def getButton(self, button): return Joystick.is_button_pressed(self.joystick, button)
L_JOYSTICK_CLICK = 9 R_JOYSTICK_CLICK = 10 WIN_BUTTON = 8 #loop to find the correct controller joystick = 0; foundController = False print "looking for controller, press A to chose the controller" while not foundController: for i in range(0,5): Joystick.update() if Joystick.is_connected(i): Joystick.update() if Joystick.is_button_pressed(i, A): foundController = True joystick = i print "found controller ", i print "buttons: ", Joystick.get_button_count(i) # used inside the class, not necessary to call from outside this class, use the other calls def getAxis(joyStickNumber, axis): size = maxValue - minValue return ((applyDeadZone(Joystick.get_axis_position(joyStickNumber, axis))/(100.0-deadZone)) * size) - minValue def getPrimaryX(): return getAxis(joystick, Joystick.X)