Created
January 16, 2014 14:04
-
-
Save antonvh/8455505 to your computer and use it in GitHub Desktop.
Getting joystick input in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sdl2 | |
sdl2.SDL_Init(sdl2.SDL_INIT_JOYSTICK) | |
joystick = sdl2.SDL_JoystickOpen(0) | |
while True: | |
sdl2.SDL_PumpEvents() | |
#depending on the gamepad this gives you a value between -32768 and +32768 | |
#or between 0 and 32768 | |
joy_x = sdl2.SDL_JoystickGetAxis(joystick, 0) | |
joy_y = sdl2.SDL_JoystickGetAxis(joystick, 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment