def test_SDL_JoystickGetBall(self): sticks = [joystick.SDL_JoystickOpen(i) for i in range(self.jcount)] numball = [joystick.SDL_JoystickNumBalls(s) for s in sticks] if not any(numball): pytest.skip("no trackball on any connected controller") dx, dy = c_int(0), c_int(0) get_ball = joystick.SDL_JoystickGetBall for stick in sticks: for ball in range(joystick.SDL_JoystickNumBalls(stick)): ret = get_ball(stick, ball, byref(dx), byref(dy)) err = SDL_GetError() assert ret == 0 assert len(err) == 0 joystick.SDL_JoystickClose(stick)
def test_SDL_JoystickNumBalls(self): for index in range(self.jcount): stick = joystick.SDL_JoystickOpen(index) assert isinstance(stick.contents, joystick.SDL_Joystick) balls = joystick.SDL_JoystickNumBalls(stick) assert balls >= 0 joystick.SDL_JoystickClose(stick)
def test_SDL_JoystickNumBalls(self): if self.jcount == 0: self.skipTest("no joysticks detected") for index in range(self.jcount): stick = joystick.SDL_JoystickOpen(index) self.assertIsInstance(stick.contents, joystick.SDL_Joystick) balls = joystick.SDL_JoystickNumBalls(stick) self.assertGreaterEqual(balls, 0) joystick.SDL_JoystickClose(stick)
def test_SDL_JoystickGetBall(self): if self.jcount == 0: self.skipTest("no joysticks detected") for index in range(self.jcount): stick = joystick.SDL_JoystickOpen(index) for ball in range(joystick.SDL_JoystickNumBalls(stick)): dx, dy = joystick.SDL_JoystickGetBall(stick, ball) self.assertIsInstance(dx, int) self.assertIsInstance(dy, int) # TODO joystick.SDL_JoystickClose(stick)
sdl2.SDL_Init(sdl2.SDL_INIT_JOYSTICK, sdl2.SDL_INIT_VIDEO) # sdl2.SDL_QuitSubSystem(sdl2.SDL_INIT_VIDEO) # 初始化 num = sdl2.joystick.SDL_NumJoysticks() keysym = keyboard.SDL_Keysym() # window = keyboard.SDL_GetKeyboardFocus() print(keysym) # keysym1 = keyboard.SDL_Keysym(1, 2, 3, ord("b")) # print(keysym1.scancode) # print(num) joystick1 = sdl2.SDL_JoystickOpen(0) # print(joystick1) # joystick.SDL_JoystickClose(joystick1) axes = joystick.SDL_JoystickNumAxes(joystick1) print('axis={}'.format(axes)) balls = joystick.SDL_JoystickNumBalls(joystick1) print('balls={}'.format(balls)) hats = joystick.SDL_JoystickNumHats(joystick1) print('hats={}'.format(hats)) buttons = joystick.SDL_JoystickNumButtons(joystick1) print('buttons={}'.format(buttons)) window = sdl2.ext.Window('Test', size=(640, 480)) window.show() key_states = sdl2.SDL_GetKeyboardState(None) # hats = joystick.SDL_JoystickNumHats(joystick1) # print(hats) # for state in (SDL_IGNORE, SDL_ENABLE): # news = joystick.SDL_JoystickEventState(state) # print(news, state) # for axis in range(joystick.SDL_JoystickNumAxes(joystick1)):