Esempio n. 1
0
    def get_hat(self, i):
        """ get_hat(hat_number) -> x, y
        get the position of a joystick hat
        """
        joydata = self._joydata
        if i < 0 or i >= sdl.SDL_JoystickNumHats(joydata):
            raise SDLError("Invalid joystick hat")
        value = sdl.SDL_JoystickGetHat(joydata, i)

        px = py = 0
        if value & sdl.SDL_HAT_UP:
            py = 1
        elif value & sdl.SDL_HAT_DOWN:
            py = -1
        if value & sdl.SDL_HAT_RIGHT:
            px = 1
        elif value & sdl.SDL_HAT_LEFT:
            px = -1

        return (px, py)
Esempio n. 2
0
 def get_numhats(self):
     """ get_numhats() -> int
     get the number of hat controls on a Joystick
     """
     return sdl.SDL_JoystickNumHats(self._joydata)