Are There Known Sdl Key Polling Issues?


authoreyes

Member
Joined
Oct 2, 2007
Messages
161
Website
www.markandmarina.com
Having a strange issue with my game in re: key event polling.

The code runs fine on 2 different ubuntu linux desktops, but on the pandora, everything is wrong. This may be my machine only? (my nubs just went out, but seems unlikely as the d-pad and face buttons work fine in everything else)

Basically, I have code that maintains state for keyevents (down and up) for fluid key repeating behavior...However, on the pandora, it constantly seem to receive false positives for keystates, causing the player to constantly jump up and down...Also, its odd, a d-pad up press kicks off the jumping behavior, when only SDL_PAGEUP should...

I'll debug it, but figured I'd see if anyone else had such issues...Again, works fine on my desktops...
 
Are you using keysym of keycode (or whatever they're called); one of them shoudl work, the other I bet doesn't, so be mindful which you're using :)

SDL key events should work fine; which keys? For d-pad and such, they work fine in the games/ports I maintain (ie: Battlejewels is my own game, and used SDL for the Pandora build; likewise Hatari and a dozen other things use SDL just fine.)

There are non-SDL ways as well, but SDL should be fine for ya.

jeff
 
skeezix said:
Are you using keysym of keycode (or whatever they're called); one of them shoudl work, the other I bet doesn't, so be mindful which you're using :)

SDL key events should work fine; which keys? For d-pad and such, they work fine in the games/ports I maintain (ie: Battlejewels is my own game, and used SDL for the Pandora build; likewise Hatari and a dozen other things use SDL just fine.)

There are non-SDL ways as well, but SDL should be fine for ya.

jeff

Originally was using the keystates array, but didn't seem to always give me the right vals (would occasionally seem to not register key up events, causing the direction to get "stuck"...Changed the code to use keysym and works perfect on the pc's, but not the pandora...It's really odd....I am refactoring some stuff now to see if I can fix it without intensive debugging :)

My game worked fine before, but I just implemented standing and running jumping today - what started the pandy headaches was this use case :

running right, do running jump, and continue to run upon landing...The original way wouldn't know that right was still in the down state - so I created a wrapper to maintain state, which works fine on pc, but the pandora...
 
Last edited by a moderator:
SWEET!

Got it working....Jeff had the right idea - it's one or the other...

For anyone else who may run into this, what works for me was this :

- grab a pointer to the Uint8 *keys = SDL_GetKeyState(NULL); Just once, outside of the render loop. SDL takes care of updating this array.
- SDL_PollEvent(&event); Do this every render pass - this internally pumps events and handles tracking the array of keystates
- Then, I still use my own state manager to track previous key values vs new to know when things changed, sinceI have different animation states depending on what's occurring. So, make sure to check the array every cycle for every key you care about like so :
int value = keys[SDLK_RIGHT]
- You can aggregate these/etc...
- Profit!

I was first just relying on the KeyState Events which worked fine on PC but not so great on Pandora - checking the array and making sure to just pump events works fine.
 
Back
Top