Newbie here, trying to make my joystick work in a simple console application.
I can’t get out my axis values, it just repeats 0.0000. Any thoughts? Do I need
to check for events?
It goes into a loop I know…
#include <stdlib.h> #include <SDL.h>
int main(int argc, char *argv[])
{
SDL_Joystick *joy;
// Initialize the joystick subsystem
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
// Check for joystick
if(SDL_NumJoysticks()>0){
// Open joystick
joy=SDL_JoystickOpen(0);
if(joy)
{
printf(“Opened Joystick 0\n”);
printf(“Name: %s\n”, SDL_JoystickName(0));
printf(“Number of Axes: %d\n”, SDL_JoystickNumAxes(joy));
printf(“Number of Buttons: %d\n”, SDL_JoystickNumButtons(joy));
printf(“Number of Balls: %d\n”, SDL_JoystickNumBalls(joy));
}
else
printf(“Couldn’t open Joystick 0\n”);
int SDL_JoystickEventState(true);
while(1) {
printf("%f",SDL_JoystickGetAxis(joy, 0));
}
return 0;
might i suggest you fix your indenting and curly bracing ? this looks
copied and pasted from 2 different sources, very difficult to read.On Fri, 18 Jul 2008, Mark wrote:
Newbie here, trying to make my joystick work in a simple console application.
I can’t get out my axis values, it just repeats 0.0000. Any thoughts? Do I need
to check for events?
It goes into a loop I know…
#include <stdlib.h> #include <SDL.h>
int main(int argc, char *argv[])
{
SDL_Joystick *joy;
// Initialize the joystick subsystem
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
// Check for joystick
if(SDL_NumJoysticks()>0){
// Open joystick
joy=SDL_JoystickOpen(0);
if(joy)
{
printf(“Opened Joystick 0\n”);
printf(“Name: %s\n”, SDL_JoystickName(0));
printf(“Number of Axes: %d\n”, SDL_JoystickNumAxes(joy));
printf(“Number of Buttons: %d\n”, SDL_JoystickNumButtons(joy));
printf(“Number of Balls: %d\n”, SDL_JoystickNumBalls(joy));
}
else
printf(“Couldn’t open Joystick 0\n”);