#include <stdio.h>
#include "SDL.h"
int main ( int argc, char *argv[] )
{
if ( SDL_InitSubSystem ( SDL_INIT_JOYSTICK ) < 0 )
{
fprintf ( stderr, "Unable to initialize Joystick: %s\n", SDL_GetError() );
return -1;
} printf ( "%i joysticks found\n", SDL_NumJoysticks () ); SDL_Joystick* joy1 = SDL_JoystickOpen ( 0 );
if ( joy1 == NULL )
printf ( "could not open joystick\n" );
printf ( "%i achsen\n", SDL_JoystickNumAxes ( joy1 ) );
printf ( "%i rollbaelle\n", SDL_JoystickNumBalls ( joy1 ) );
printf ( "%i heads\n", SDL_JoystickNumHats ( joy1 ) );
printf ( "%i koepfe\n", SDL_JoystickNumButtons ( joy1 ) ); SDL_JoystickEventState ( SDL_QUERY );
while ( 1 )
{ SDL_JoystickUpdate (); for ( int i=0; i < SDL_JoystickNumButtons ( joy1 ); ++i )
{
unsigned int n = SDL_JoystickGetButton ( joy1, i );
if ( n != 0 )
printf ( "found you pressed button %i\n", i );
}
for ( int i=0; i < SDL_JoystickNumAxes ( joy1 ); ++i )
{
signed short a = SDL_JoystickGetAxis ( joy1, i );
if ( a != 0 )
printf ( "axis %i is %d\n", i,a );
}
}
return 0;
}