Is there an easy way of using SDL for text input such as entering the
player’s name or implementing a in-game chat room?
Polling for SDL_KEYDOWN events and determining what key was pressed,
then mapping it the corresponding ASCII character seems to be the only
way but it is
quite involved. Checking for modifiers(KMOD_CAPS, KMOD_RSHIFT ,KMOD_
LSHIFT, KMOD_SHIFT) , filtering out invalid keys(F1-F12, arrow keys,
Insert, Home, etc) from the event, converting keys based on shift
state(e.g. 1 to ! 2 to @ 3 to #), becomes a hassle.
Is there an easier way, like in GLUT such as: glutKeyboardFunc(unsigned
char key), which key would be ‘A’ if shift is down(or capslock is on)
and ‘b’ if shift is
up(or capslock is off)?
in my game i have both buffered text input (enter your name) and also
control input (pressing left and up at the same time to move diagonaly).
What i do is enable unicode first off, then i watch for keydown events and
add the keys (Event.key.keysym.unicode) to a queue. So, when i want
buffered input, as soon as buffered input is started, i empty the queue and
then have a loop that processes the keys from the queue into a text box as
they come in (waiting for return key, button press etc) and when i dont want
buffered input i just ignore the queue and just use SDL_GetKeyState to check
for control keys.
Does this make any sense? I hope so
Atrix> ----- Original Message -----
From: cyansoft@hotmail.com (cyansoft)
To:
Sent: Saturday, August 23, 2003 11:07 AM
Subject: [SDL] Keyboard: Enter your name
Is there an easy way of using SDL for text input such as entering the
player’s name or implementing a in-game chat room?
Polling for SDL_KEYDOWN events and determining what key was pressed,
then mapping it the corresponding ASCII character seems to be the only
way but it is
quite involved. Checking for modifiers(KMOD_CAPS, KMOD_RSHIFT ,KMOD_
LSHIFT, KMOD_SHIFT) , filtering out invalid keys(F1-F12, arrow keys,
Insert, Home, etc) from the event, converting keys based on shift
state(e.g. 1 to ! 2 to @ 3 to #), becomes a hassle.
Is there an easier way, like in GLUT such as: glutKeyboardFunc(unsigned
char key), which key would be ‘A’ if shift is down(or capslock is on)
and ‘b’ if shift is
up(or capslock is off)?