Skip to content

Instantly share code, notes, and snippets.

@antonvh
Created January 16, 2014 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonvh/8455505 to your computer and use it in GitHub Desktop.
Save antonvh/8455505 to your computer and use it in GitHub Desktop.
Getting joystick input in python
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