I have an application which runs on SDL(simple directmedia layer). I've ported it to SDL2. But after porting, joystick(SDL_PollEvent) is only captures the release event of joysticks button. Is there anything wrong or is there any setting for capturing press events in SDL2?
Asked
Active
Viewed 632 times
2 Answers
3
I have a loop and swich statement too.I could get only release events of joystick button by this loop.
I found the answer a few seconds ago. If I call SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,"1") before SDL_Init statement, joystick button gets press and release events, otherwise polling can not capture press event.

zacoder
- 91
- 11
-
This worked for me, as well. I made a game engine that will load a map when you press a button (joystick button, in this case) and wouldn't call the "release" event if you pressed & released too quickly. It seems as though the game is considered "in the background" while processing through some library (for example, libzip. who knows). If anyone else has this problem, here's some more documentation:https://wiki.libsdl.org/SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS – Brandon Jan 04 '17 at 23:42
0
You can achieve this by using a switch statement for example:
while( SDL_PollEvent( &event ) )
{
switch( event.type )
{
case SDL_KEYDOWN:
printf( "Key pressed" );
break;
default:
break;
}
}
I don't see that anything has changed in particular about this.
Also it wouldn't make sense to remove this functionality so my guess is that you might be doing something wrong.

deW1
- 5,562
- 10
- 38
- 54