Reputation: 69
How do you detect simultaneous key repeats with SDL? Right now I can detect keys pressed at the same time (but not if they are all held down) or a single key held down. I want to be able to detect all the keys that are held down at any one time.
My code
SDL_EnableKeyRepeat (100, 200);
while (SDL_PollEvent (&event)) {
if (event.type == SDL_KEYDOWN) {
if (event.key.keysym.sym == SDLK_t) {
} else if (event.key.keysym.sym == SDL_y) {
}
} else if (blah) {
//blah blah blah
}
}
Upvotes: 0
Views: 1021
Reputation: 2503
First detecting all keys that are held down might prove impossible. Due to keyboard limitations, most keyboards support 4-6 buttons pressed at the same time, after that key presses/releases wont register. Second i wouldn't suggest using key repeat. Dunno maybe other peoples experience differs, but you can get better accuracy by storing states of keys that interest you. I.e. in simple game that would be directional keys. And you just set moving left when left is pressed, and unset it when left is released or maybe when right is pressed. If you need it for something like typing you could probably make it using some array pressed_keys and put key ids there of keys that are pressed. (Im assuming your trying to make something game like).
Upvotes: 1