#include #include #include #include #include SDL_Event event; SDL_Joystick *joystick; int main (int argc, char *argv[]) { char *msg; int done = 0; SDL_InitSubSystem(SDL_INIT_JOYSTICK); SDL_JoystickEventState(SDL_ENABLE); // enable the joystick events (SDL_IGNORE to disable them) joystick = SDL_JoystickOpen(0); // read from the joystick n°0 /* Initialize SDL: joystick and video mode (to display something on the screen) */ if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) { sprintf (msg, "Couldn't initialize SDL: %s\n", SDL_GetError ()); MessageBox (0, msg, "Error", MB_ICONHAND); free (msg); exit (1); } while (!done) { SDL_PollEvent (&event); switch(event.type) { case SDL_JOYBUTTONDOWN: if (event.jbutton.button == 1) { /* do whatever we want if the button n°1 is pressed for instance */ } break; case SDL_JOYAXISMOTION: if(event.jaxis.axis == 0 && event.jaxis.value < - 2000) /* do whatever we want when the axis is moved left for instance */ break; default: break; } } SDL_JoystickClose(joystick); return 0; }