Getting text input

Is there a simple way of getting the character pressed, besides
having a switch with a case for every key? I don’t need a GUI
library, or special characters, just the basic letters.

case SDLK_FOO:
str += bar;
break;

–jake__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/

this question was asked just some time ago--------------------

this should be posted in a faq or something.
this question comes up far too often and the solution is so damn easy.

David Olofson wrote:

On Friday 21 May 2004 12.20, Andr? Stein wrote:

Hi all,

I am wondering whether it's possible with SDL to get the "real"

character pressed during a keydown event… It seems like SDL
doesn’t make a difference between e.g. a and A and translates it to
the same virtual key code. If you’d like to implement a textfield
to type for example the user’s username - case senitive - the
solution to go for is to handle the shift event and so toggle the
next character. But this workaround wouldn’t care about special
chars especially on international keyboards.

So in other terms is there a nice & beautiful solution how to use
SDL key down events to get the real pressed char like in any
Qt/Win32 textfield?

Forget about scan codes, qualifier keys and stuff. You’ll just get a
headache and a non-portable and/or missbehaved application.

In your initialization:

SDL_EnableUNICODE(1);

and then when you get a keyboard event: (From ‘man SDL_keysym’)

if(!(event.key.keysym.unicode & 0xff80))
    ascii = event.key.keysym.unicode;
else
    <deal with international characters>;

This method actually works, even with weird keyboard layouts like my
custom swedish Dvorak variant. :slight_smile:

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

jake b wrote:

Is there a simple way of getting the character pressed, besides
having a switch with a case for every key? I don’t need a GUI
library, or special characters, just the basic letters.

case SDLK_FOO:
str += bar;
break;

–jake


Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

SDL_EnableUNICODE()
This has been asked a million times - search in the archive!

jake b wrote:> Is there a simple way of getting the character pressed, besides

having a switch with a case for every key? I don’t need a GUI
library, or special characters, just the basic letters.

case SDLK_FOO:
str += bar;
break;

–jake


Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

The SDL docs really suck, if no one’s going to maintain them, they
should be wiki’d so the users can do it.

Bernhard Bliem wrote:> SDL_EnableUNICODE()

This has been asked a million times - search in the archive!

jake b wrote:

Is there a simple way of getting the character pressed, besides
having a switch with a case for every key? I don’t need a GUI
library, or special characters, just the basic letters.

case SDLK_FOO:
str += bar;
break;

–jake


Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

definately!

i’d even volunteer to migrate the sdl docu into a wiki.
i think i’ve alrady offered this several times…

Tyler Zesiger wrote:> The SDL docs really suck, if no one’s going to maintain them, they

should be wiki’d so the users can do it.

Bernhard Bliem wrote:

SDL_EnableUNICODE()
This has been asked a million times - search in the archive!

jake b wrote:

Is there a simple way of getting the character pressed, besides
having a switch with a case for every key? I don’t need a GUI
library, or special characters, just the basic letters.

case SDLK_FOO:
str += bar;
break;

–jake

       __________________________________

Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

definately!

i’d even volunteer to migrate the sdl docu into a wiki.
i think i’ve alrady offered this several times…

Okay, I’m convinced. I never got any response from Martin, so the
SDL documentation project is hereby in limbo. To take up the torch
I need a few people who are interested in helping me set up a wiki
on libsdl.org and people interested in updating and maintaining it.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment