SDL2 - 2.0.8 - Ubuntu 18.04 - Joystick Button event issue

I’m testing some game joystick and would like to track when 2 or more buttons are pressed simultaneously or not and keep track of the pressed button status.

The problem is if i press Button 1 (and keep it pressed) and then press Button 0 (and keep it pressed), Button 1 receives an release event. I should expect only Button 0 press event.

Events received:

Button 1 pressed. e.type:1539
Button 0 pressed. e.type:1539
Button 1 released. e.type:1540 (should not receive this event when Button 0 pressed, Button 1 and 0 still pressed)

Buttons 16:
0: 0
1: 0

Expected results:

Button 1 pressed. e.type:1539
Button 0 pressed. e.type:1539

Buttons 16:
0: 0
1: 0

I tested 2 joystick from different makers, same behavior. I also tested the joystick online, got the same result.

I wonder if it is a hardware limitation, sdl2 logic or i am missing something. It happens with any combination of buttons.

Any thoughts?

1 Like

I agree, this is not the right behaviour.
2.0.8 is quite old. Maybe try a newer version.

Not sure i can build newer version without breaking the distro, i need alsa and all the stuff already working.

If you or other can just test the behavior on newer versions i would appreciate.

I have the impression that the kernel version matters also.

5.4.0-55-generic #61~18.04.1-Ubuntu

Here is the game pads i am testing/using (6 axis):

Tested online with: https://gamepadtest.com/

Okay, tested with SDL3

– Platform: Linux-5.4.0-55-generic
– 64-bit: TRUE
– Compiler: /usr/bin/cc
– Revision: SDL-3.3.0-6d47d8d

Exact same behavior.

Can we please see a snippet of your event handling code? I suspect a missing break in one of your switch-cases, but that’s just a guess without seeing it.
I don’t usually use the joystick API, but I have not run into this issue with SDL3’s gamepad API, which should work pretty well with the devices you have shown.

I have the playstation style one myself and it works fine with the gamepad API.

I tested on Debian 9.13 (stretch) which uses SDL 2.0.5 (an even older version than yours) and it worked as expected, both with SDL and at gamepadtest.com.

Thank you all for the feedback.

There seems to be a hardware limitation in the gamepad for the buttons I tested. In the PlayStation style, the face buttons worked. Perhaps the one i tested are not designed for multiple simultaneous presses.

Just for the record, here is the SDL2 snippet code:

// Game loop
while (!quit) {
// Handle events on queue
while (SDL_PollEvent(&e) != 0) {
// User requests quit
if (e.type == SDL_QUIT) {
quit = 1;
}
// Joystick button pressed
else if (e.type == SDL_JOYBUTTONDOWN) {
printf(“Button %d pressed. type:%d\n”, e.jbutton.button, e.type);
}
// Joystick button released
else if (e.type == SDL_JOYBUTTONUP) {
printf(“Button %d released. type:%d\n”, e.jbutton.button, e.type);
}
// Joystick axis motion
else if (e.type == SDL_JOYAXISMOTION) {
// Motion on axis 0 (X-axis) or 1 (Y-axis)
if (e.jaxis.axis >= 0 || e.jaxis.axis == 1) {
printf(“Axis %d moved to %d\n”, e.jaxis.axis, e.jaxis.value);
}
}
// Joystick hat motion
else if (e.type == SDL_JOYHATMOTION) {
printf(“Hat %d moved to %d\n”, e.jhat.hat, e.jhat.value);
}
}
}

Here are the events generated (or not generated, pushing button1, holding it and pushing button 2 and holding it, and at last releasing buttons and pushing button 2):

/dev/input/event13: 广东聚慧飞科技 穿越机手柄
Select the device event number [0-13]: 13
Input driver version is 1.0.1
Input device ID: bus 0x3 vendor 0x1209 product 0x4f54 version 0x111
Input device name: “广东聚慧飞科技 穿越机手柄”
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 288 (BTN_TRIGGER)
Event code 289 (BTN_THUMB)
Event code 290 (BTN_THUMB2)
Event code 291 (BTN_TOP)
Event code 292 (BTN_TOP2)
Event code 293 (BTN_PINKIE)
Event code 294 (BTN_BASE)
Event code 295 (BTN_BASE2)
Event code 296 (BTN_BASE3)
Event code 297 (BTN_BASE4)
Event code 298 (BTN_BASE5)
Event code 299 (BTN_BASE6)
Event code 300 (?)
Event code 301 (?)
Event code 302 (?)
Event code 303 (BTN_DEAD)
Event type 3 (EV_ABS)
Event code 0 (ABS_X)
Value 128
Min 0
Max 250
Flat 15
Event code 1 (ABS_Y)
Value 129
Min 0
Max 250
Flat 15
Event code 2 (ABS_Z)
Value 12
Min 0
Max 250
Flat 15
Event code 3 (ABS_RX)
Value 128
Min 0
Max 250
Flat 15
Event code 4 (ABS_RY)
Value 113
Min 0
Max 250
Flat 15
Event code 5 (ABS_RZ)
Value 130
Min 0
Max 250
Flat 15
Event type 4 (EV_MSC)
Event code 4 (MSC_SCAN)
Properties:
Testing … (interrupt to exit)
Event: time 1759753934.742824, type 3 (EV_ABS), code 3 (ABS_RX), value 129
Event: time 1759753934.742824, -------------- SYN_REPORT ------------
Event: time 1759753934.774825, type 3 (EV_ABS), code 3 (ABS_RX), value 128
Event: time 1759753934.774825, -------------- SYN_REPORT ------------
Event: time 1759753934.870822, type 3 (EV_ABS), code 3 (ABS_RX), value 129
Event: time 1759753934.870822, -------------- SYN_REPORT ------------
Event: time 1759753934.902824, type 3 (EV_ABS), code 3 (ABS_RX), value 128
Event: time 1759753934.902824, -------------- SYN_REPORT ------------
Event: time 1759753936.278812, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90001
Event: time 1759753936.278812, type 1 (EV_KEY), code 288 (BTN_TRIGGER), value 1
Event: time 1759753936.278812, -------------- SYN_REPORT ------------
Event: time 1759753937.462803, type 3 (EV_ABS), code 1 (ABS_Y), value 128
Event: time 1759753937.462803, -------------- SYN_REPORT ------------
Event: time 1759753937.494806, type 3 (EV_ABS), code 1 (ABS_Y), value 129
Event: time 1759753937.494806, type 3 (EV_ABS), code 3 (ABS_RX), value 129
Event: time 1759753937.494806, -------------- SYN_REPORT ------------
Event: time 1759753937.526804, type 3 (EV_ABS), code 3 (ABS_RX), value 128
Event: time 1759753937.526804, -------------- SYN_REPORT ------------
Event: time 1759753940.950776, type 3 (EV_ABS), code 1 (ABS_Y), value 128
Event: time 1759753940.950776, -------------- SYN_REPORT ------------
Event: time 1759753940.982779, type 3 (EV_ABS), code 1 (ABS_Y), value 129
Event: time 1759753940.982779, -------------- SYN_REPORT ------------
Event: time 1759753941.494774, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90001
Event: time 1759753941.494774, type 1 (EV_KEY), code 288 (BTN_TRIGGER), value 0
Event: time 1759753941.494774, -------------- SYN_REPORT ------------
Event: time 1759753943.382758, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90002
Event: time 1759753943.382758, type 1 (EV_KEY), code 289 (BTN_THUMB), value 1
Event: time 1759753943.382758, -------------- SYN_REPORT ------------
Event: time 1759753944.214752, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90002
Event: time 1759753944.214752, type 1 (EV_KEY), code 289 (BTN_THUMB), value 0
Event: time 1759753944.214752, -------------- SYN_REPORT ------------