KeyboardHandler in SDL

has anyone any niceway todo a keyboard handler in SDL
if i use SDL_KEYDOWN event i would get thousands of the same character in
my buffer…

i would need a way to when i get a character put it in my buffer then
remove the event so it wont be triggered again before the key is released
and pressed again!

is there any easy way

/andreas

i would need a way to when i get a character put it in my buffer then
remove the event so it wont be triggered again before the key is released
and pressed again!

Create an array of keys. When you get a KEYDOWN event, set that key’s
element to 1. Ignore KEYDOWNs while that element is 1, then when you get
a KEYUP event, set it back to 0.

There’s probably a more normal way to do it, as well, but this would be
pretty easy.

-ChuckOn Tue, 27 Apr 1999, Andreas Karlsson wrote:

has anyone any niceway todo a keyboard handler in SDL
if i use SDL_KEYDOWN event i would get thousands of the same character in
my buffer…

i would need a way to when i get a character put it in my buffer then
remove the event so it wont be triggered again before the key is released
and pressed again!

is there any easy way

This is really frustrating. The way to do it is to turn off keyrepeat,
but under X11, you can’t turn off the keyrepeat for a particular window -
you have to do it for the entire display. In addition, keyrepeat is
simulated by keypresses followed by keyreleases, so you can’t just check
the existing key state to see if the event is a keyrepeat event.

Any ideas?

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

This is really frustrating. The way to do it is to turn off keyrepeat,
but under X11, you can’t turn off the keyrepeat for a particular window -
you have to do it for the entire display. In addition, keyrepeat is
simulated by keypresses followed by keyreleases, so you can’t just check
the existing key state to see if the event is a keyrepeat event.

Any ideas?

When I code interactive X11 stuff (ie, games), I usually do it like the
last person suggested… keep an array of the keys I’m interested in.
When an event comes in for that key, I copy it’s value (either a
KeyPress or a KeyRelease event… they’re just int’s) into the key’s slot
in the array.

Depending on what I’m doing, I may care whether or not this key was
just pressed, or simply whether or not it’s being pressed right now.
(For menu selections, you want the former, otherwise the menu would be
impossible to use. For sliding an animated character around in a window,
you want the former.)

Unfortunately, though, I have to admit I haven’t played much with SDL events,
since I’ve just gotten into SDL and haven’t started any real new projects
using it (I just used SDL to add really nice sound/music to my old Xlib
programs :slight_smile: )

-bill!
bill at newbreedsoftware.com
http://www.newbreedsoftware.com/