Пример #1
0
 def test_SDL_JoystickGetHat(self):
     hatvals = [
         joystick.SDL_HAT_UP, joystick.SDL_HAT_DOWN, joystick.SDL_HAT_LEFT,
         joystick.SDL_HAT_RIGHT, joystick.SDL_HAT_CENTERED,
         joystick.SDL_HAT_LEFTUP, joystick.SDL_HAT_LEFTDOWN,
         joystick.SDL_HAT_RIGHTUP, joystick.SDL_HAT_RIGHTDOWN
     ]
     sticks = [joystick.SDL_JoystickOpen(i) for i in range(self.jcount)]
     numhats = [joystick.SDL_JoystickNumHats(s) for s in sticks]
     if not any(numhats):
         pytest.skip("no POV hat on any connected controller")
     for stick in sticks:
         for hat in range(joystick.SDL_JoystickNumHats(stick)):
             val = joystick.SDL_JoystickGetHat(stick, hat)
             assert val in hatvals
         joystick.SDL_JoystickClose(stick)
Пример #2
0
 def test_SDL_JoystickNumHats(self):
     for index in range(self.jcount):
         stick = joystick.SDL_JoystickOpen(index)
         assert isinstance(stick.contents, joystick.SDL_Joystick)
         hats = joystick.SDL_JoystickNumHats(stick)
         assert hats >= 0
         joystick.SDL_JoystickClose(stick)
Пример #3
0
 def test_SDL_JoystickNumHats(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)
         hats = joystick.SDL_JoystickNumHats(stick)
         self.assertGreaterEqual(hats, 0)
         joystick.SDL_JoystickClose(stick)
Пример #4
0
 def test_SDL_JoystickGetHat(self):
     if self.jcount == 0:
         self.skipTest("no joysticks detected")
     for index in range(self.jcount):
         stick = joystick.SDL_JoystickOpen(index)
         for hat in range(joystick.SDL_JoystickNumHats(stick)):
             val = joystick.SDL_JoystickGetHat(stick, hat)
             self.assertIsInstance(val, int)
             # TODO
         joystick.SDL_JoystickClose(stick)
Пример #5
0
#  初始化
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)):
#     val = joystick.SDL_JoystickGetAxis(joystick1, axis)
#     print(val, axis)