Example #1
0
    def __init__(self, id):
        """An object to control a multi-axis joystick or gamepad

        .. note:

            You do need to be flipping frames (or dispatching events manually)
            in order for the values of the joystick to be updated.

        :Known issues:

            Currently under pyglet backends the axis values initialise to zero
            rather than reading the current true value. This gets fixed on the
            first change to each axis.
        """
        self.id=id
        if backend=='pyglet':
            joys=pyglet_input.get_joysticks()
            if id>=len(joys):
                logging.error("You don't have that many joysticks attached (remember that the first joystick has id=0 etc...)")
            else:
                self._device=joys[id]
                self._device.open()
                self.name=self._device.device.name
            if len(visual.openWindows)==0:
                logging.error("You need to open a window before creating your joystick")
            else:
                for win in visual.openWindows:
                    win._eventDispatchers.append(self._device.device)
        else:
            pygame.joystick.init()
            self._device=pygame.joystick.Joystick(id)
            self._device.init()
            self.name=self._device.get_name()
def getNumJoysticks():
    """Return a count of the number of joysticks available.
    """
    if backend == 'pyglet':
        return len(pyglet_input.get_joysticks())
    else:
        pygame.joystick.init()
        return pygame.joystick.get_count()
Example #3
0
def getNumJoysticks():
    """Return a count of the number of joysticks available.
    """
    if backend=='pyglet':
        return len(pyglet_input.get_joysticks())
    else:
        pygame.joystick.init()
        return pygame.joystick.get_count()
    def __init__(self, id):
        """An object to control a multi-axis joystick or gamepad

        .. note:

            You do need to be flipping frames (or dispatching events manually)
            in order for the values of the joystick to be updated.

        :Known issues:

            Currently under pyglet backends the axis values initialise to zero
            rather than reading the current true value. This gets fixed on the
            first change to each axis.
        """
        self.id = id
        if backend == 'pyglet':
            joys = pyglet_input.get_joysticks()
            if id >= len(joys):
                logging.error(
                    "You don't have that many joysticks attached (remember that the first joystick has id=0 etc...)"
                )
            else:
                self._device = joys[id]
                self._device.open()
                self.name = self._device.device.name
            if len(visual.openWindows) == 0:
                logging.error(
                    "You need to open a window before creating your joystick")
            else:
                for win in visual.openWindows:
                    win._eventDispatchers.append(self._device.device)
        else:
            pygame.joystick.init()
            self._device = pygame.joystick.Joystick(id)
            self._device.init()
            self.name = self._device.get_name()