Question about joysticks

i tested this with 2 joysticks same result, when i press each hat (dpad) button the MOTION event is dispatched and everything is ok, but when i press let say 2 at the same time, and then quick tried to press another the event is no longer active, although im pressing only one button at the end, i have to release and press again to work. is this normal? does it work like that for every kind of joystick?

Some months ago, I’ve observed this, too! But I still don’t know whether
it’s my fault , or if this really is a bug.
If I remeber corrtectly, I worked around this problem by reseting my
internal “hat-state-array” on each SDL “hat-event”. :)> i tested this with 2 joysticks same result, when i press each hat

(dpad) button the MOTION event is dispatched and <everything is ok,
but when i press let say 2 at the same time, and then quick tried to
press another the event is no longer active, although im pressing only
one button at the end, i have to release and press again to work. is
this normal? does it work like that for every kind of joystick?

well, thats the thing, the SDL_JOYHATMOTION event is not been dispatched
after that.

2014-03-03 15:22 GMT-07:00 Julian Winter :>

Some months ago, I’ve observed this, too! But I still don’t know whether
it’s my fault , or if this really is a bug.
If I remeber corrtectly, I worked around this problem by reseting my
internal “hat-state-array” on each SDL “hat-event”. :slight_smile:

i tested this with 2 joysticks same result, when i press each hat (dpad)

button the MOTION event is dispatched and <everything is ok, but when i
press let say 2 at the same time, and then quick tried to press another the
event is no longer active, although im pressing only one button at the end,
i have to release and press again to work. is this normal? does it work
like that for every kind of joystick?


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


Javier Flores

is there a difference between SDL_GameController and SDL_Joystick that would fix this?

is there a difference between SDL_GameController and SDL_Joystick that would fix this?

Not really… the GameController API sits on top of the Joystick API. it?s simply a mapping layer to map button, axis, and hat events into a uniform simple ?xbox 360-like? layout to make controller integration into games much simpler.On Mar 4, 2014, at 2:36 AM, javierecf wrote:


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

Julian Winter wrote:> Some months ago, I’ve observed this, too! But I still don’t know whether

it’s my fault , or if this really is a bug.
If I remeber corrtectly, I worked around this problem by reseting my
internal “hat-state-array” on each SDL “hat-event”. :slight_smile:

i tested this with 2 joysticks same result, when i press each hat
(dpad) button the MOTION event is dispatched and <everything is ok,
but when i press let say 2 at the same time, and then quick tried to
press another the event is no longer active, although im pressing only
one button at the end, i have to release and press again to work. is
this normal? does it work like that for every kind of joystick?

Julian, what model of joystick are you using?, im using only generics, same results everytime, the event is not been dispatched after pressing buttons at the same time.
can you provide me a little insight in your event loop? maybe im doin something wrong there. but its weird, cause i do the same thing with the keyboard, and that works well.

this is my event loop:

Code:
void Main::onEvent(SDL_Event *e){

switch(e->type){
    case SDL_QUIT:
        quit = true;
        break;

    case SDL_KEYDOWN:
        keys[SSTR(e->key.keysym.sym)] = true;
        break;

    case SDL_KEYUP:
        keys[SSTR(e->key.keysym.sym)] = false;
        break;

    case SDL_WINDOWEVENT:
        switch(e->window.event){
            case SDL_WINDOWEVENT_MOVED:
                FPS::FPSControl.fps = 0;
                break;
        } break;


    case SDL_JOYAXISMOTION:
        //trace("axis");
        //trace(SSTR(e->jaxis.value));
        if ( (e->jaxis.value < -3200) || (e->jaxis.value > 3200) ) {
            //trace(SSTR(e->jaxis.value));
            if( e->jaxis.axis == 0) {
                if(sign(e->jaxis.value)==-1) controlLeft = true;
                if(sign(e->jaxis.value)==1) controlRight = true;
            }

            if( e->jaxis.axis == 1) {
                if(sign(e->jaxis.value)==-1) controlUp = true;
                if(sign(e->jaxis.value)==1) controlDown = true;
            }

        }else{
            //no movement on the axis
            controlLeft = false;
            controlRight = false;
            controlUp = false;
            controlDown = false;
        }
        break;

    case SDL_JOYHATMOTION:
        //trace("hat");
        if (e->jhat.value == SDL_HAT_CENTERED){
            controlLeft = false;
            controlRight = false;
            controlUp = false;
            controlDown = false;
        }
        if (e->jhat.value & SDL_HAT_UP) controlUp = true;
        if (e->jhat.value & SDL_HAT_DOWN) controlDown = true;
        if (e->jhat.value & SDL_HAT_RIGHT) controlRight = true;
        if (e->jhat.value & SDL_HAT_LEFT) controlLeft = true;

        break;

    case SDL_JOYBUTTONDOWN:
        //SDL_Log("Joystick %d button %d down\n",e->jbutton.which, e->jbutton.button);
        switch (e->jbutton.button){
            case 1:
                controlJump = true; break;
            case 7:
                quit = true; break;
        }
        break;

    case SDL_JOYBUTTONUP:
        //SDL_Log("Joystick %d button %d up\n",e->jbutton.which, e->jbutton.button);
        switch (e->jbutton.button){
            case 1:
                controlJump = false; break;
        }
        break;

}

}


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

My trick is to “reset” (for example) ‘controlLeft’ to “false” everytime (or on
every event-update)!
Plus, you should make sure that either left or right are set to true. Not both
at the same time.

controlLeft = false;
controlRight = false;
controlUp = false;
controlDown = false;

if (e->jhat.value & SDL_HAT_UP) controlUp = true;
else if (e->jhat.value & SDL_HAT_DOWN) controlDown = true;

if (e->jhat.value & SDL_HAT_RIGHT) controlRight = true;
else if (e->jhat.value & SDL_HAT_LEFT) controlLeft = true;> javierecf hat am 6. M?rz 2014 um 06:35 geschrieben:

Julian Winter wrote:
Some months ago, I’ve observed this, too! But I still don’t know whether
it’s my fault , or if this really is a bug.
If I remeber corrtectly, I worked around this problem by reseting my
internal “hat-state-array” on each SDL “hat-event”. [Smile]

Quote:
i tested this with 2 joysticks same result, when i press each hat

but when i press let say 2 at the same time, and then quick tried to
press another the event is no longer active, although im pressing only
one button at the end, i have to release and press again to work. is
this normal? does it work like that for every kind of joystick?

Julian, what model of joystick are you using?, im using only generics, same
results everytime, the event is not been dispatched after pressing buttons at
the same time.
can you provide me a little insight in your event loop? maybe im doin
something wrong there. but its weird, cause i do the same thing with the
keyboard, and that works well.

this is my event loop:

Code:
void Main::onEvent(SDL_Event *e){

 switch(e->type){
     case SDL_QUIT:
         quit = true;
         break;

     case SDL_KEYDOWN:
         keys[SSTR(e->key.keysym.sym)] = true;
         break;

     case SDL_KEYUP:
         keys[SSTR(e->key.keysym.sym)] = false;
         break;

     case SDL_WINDOWEVENT:
         switch(e->window.event){
             case SDL_WINDOWEVENT_MOVED:
                 FPS::FPSControl.fps = 0;
                 break;
         } break;


     case SDL_JOYAXISMOTION:
         //trace("axis");
         //trace(SSTR(e->jaxis.value));
         if ( (< -3200>) || (e->jaxis.value > 3200) ) {
             //trace(SSTR(e->jaxis.value));
             if( e->jaxis.axis == 0) {
                 if(sign(e->jaxis.value)==-1) controlLeft = true;
                 if(sign(e->jaxis.value)==1) controlRight = true;
             }

             if( e->jaxis.axis == 1) {
                 if(sign(e->jaxis.value)==-1) controlUp = true;
                 if(sign(e->jaxis.value)==1) controlDown = true;
             }

         }else{
             //no movement on the axis
             controlLeft = false;
             controlRight = false;
             controlUp = false;
             controlDown = false;
         }
         break;

     case SDL_JOYHATMOTION:
         //trace("hat");
         if (e->jhat.value == SDL_HAT_CENTERED){
             controlLeft = false;
             controlRight = false;
             controlUp = false;
             controlDown = false;
         }
         if (e->jhat.value & SDL_HAT_UP) controlUp = true;
         if (e->jhat.value & SDL_HAT_DOWN) controlDown = true;
         if (e->jhat.value & SDL_HAT_RIGHT) controlRight = true;
         if (e->jhat.value & SDL_HAT_LEFT) controlLeft = true;

         break;

     case SDL_JOYBUTTONDOWN:
         //SDL_Log("Joystick %d button %d down\n",e->jbutton.which,

e->jbutton.button);
switch (e->jbutton.button){
case 1:
controlJump = true; break;
case 7:
quit = true; break;
}
break;

     case SDL_JOYBUTTONUP:
         //SDL_Log("Joystick %d button %d up\n",e->jbutton.which,

e->jbutton.button);
switch (e->jbutton.button){
case 1:
controlJump = false; break;
}
break;

 }

}


SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

thanks a lot, now is working, but my joysticks have some issues at the moment, can you recommend a model or just a 360 controller would do the job?

You’re welcome.
I only have 360s here. :)> thanks a lot, now is working, but my joysticks have some issues at the

moment, can you recommend a model or just a 360 controller would do
the job?


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