SDL2 Joystick Events not working

Updating my 3d app plugin to make use of SDL2 so I can stop having my users install frameworks and dll files (since the new licensing in SDL2 allows static linking). According to the migration guide nothing has changed in joystick handling using events except joysticks are referenced by an instance id instead of their index. Ok, so I change up my code to reference the instance id… problem is it doesn’t work. No events ever occur. Well, I guess I should clarify that. I get one single event per joystick attached… just one and that’s it.

I tried the testjoystick program but that doesn’t work either (doesn’t launch a window that is supposedly where the joystick outputs to). I get the terminal window that outputs info about the joysticks attached, but no joystick events.

So my question is, does anyone have example code of a joystick event loop for SDL2 that actually works?

I’m on a mac if it turns out I’ve discovered a bug or something, will test on windows if it seems like that’s the case.

thanks,
Kevin

I tried the testjoystick program but that doesn’t work either (doesn’t
launch a window that is supposedly where the joystick outputs to). I get
the terminal window that outputs info about the joysticks attached, but
no joystick events.

Run “./testjoystick 0” instead of “./testjoystick” (“0” being the index
of the joystick you’d like to see input data from).

–ryan.

Thanks Ryan, I am now able to get input from a device using the test app. Still doesn’t explain why my code doesn’t work since, besides filling some variables for my plugin to make use of, it’s nearly identical to what the test app does. Maybe it has something to do with my joystick variables being created and filled in a local context outside of the event loop function? Maybe SDL2 doesn’t like that, where as it didn’t make any difference in 1.x. I’ll try making the joysticks a class variable with a wider scope when I get home from work and see if that does the trick (fingers crossed!).

Thanks,
Kevin

“kvb” writes:

Updating my 3d app plugin to make use of SDL2 so I can stop having my
users install frameworks and dll files (since the new licensing in
SDL2 allows static linking). According to the migration guide nothing
has changed in joystick handling using events except joysticks are
referenced by an instance id instead of their index. Ok, so I change
up my code to reference the instance id… problem is it doesn’t work.
No events ever occur. Well, I guess I should clarify that. I get one
single event per joystick attached… just one and that’s it.

Did you open the joystick?–
Alberto

Yes, I open all joysticks on the system right after starting SDL.

Try building sdl2 from source instead of using the framework.On 2013-11-01 4:40 PM, “kvb” wrote:

**
Yes, I open all joysticks on the system right after starting SDL.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I’ve the same issue. I ported my game from SDL to SDL2, and ran

  if(!SDL_WasInit(SDL_INIT_JOYSTICK) &&

SDL_InitSubSystem(SDL_INIT_JOYSTICK))
{
cerr<<“Unable to initialize the joystick subsystem”<<endl;
return false;
}

This then lets me detect the joystick and output its name, but none of my
event handling works, such as:

135 if ( event.jhat.value & SDL_HAT_RIGHT )
136 {
137 /* Do right stuff here */
138 character.directionX = RIGHT;
139 level.directionX = RIGHT;
140 }–
View this message in context: http://sdl.5483.n7.nabble.com/SDL2-Joystick-Events-not-working-tp37763p37879.html
Sent from the SDL mailing list archive at Nabble.com.

Do you use openGL per chance?

I have torn the joytest.c file down to a nothing but a window and the while
loop that outputs to the terminal the changes in the controller (like when a
button is pushed).

This all works.

When I take out the window creation (leaving the init the same) and instead
create an openGL context window, the application fails.

Everything works until I OpenGL-ify the app, then it won’t recognize events
just the same.–
View this message in context: http://sdl.5483.n7.nabble.com/SDL2-Joystick-Events-not-working-tp37763p37887.html
Sent from the SDL mailing list archive at Nabble.com.

mikelwrnc wrote:

Try building sdl2 from source instead of using the framework. On 2013-11-01 4:40 PM, “kvb” <@kvb (@kvb)> wrote:

   	Yes, I open all joysticks on the system right after starting SDL.

SDL mailing list
SDL at lists.libsdl.org (SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org (http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

I’m not using the supplied framework, I’m building from source and have tested using both the framework and static library.

While chances are this is not the problem, I’m still checking:

Is joystick event handling enabled using SDL_JoystickEventState?

NY00123 wrote:

While chances are this is not the problem, I’m still checking:

Is joystick event handling enabled using SDL_JoystickEventState?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Yep, it’s enabled.

“kvb” writes:

I tried the testjoystick program but that doesn’t work either (doesn’t
launch a window that is supposedly where the joystick outputs to). I
get the terminal window that outputs info about the joysticks
attached, but no joystick events.

How do you ran testjoystick? Try something like

testjoystick 0–
Alberto