Skip to main content
GameDev.net gamedev.net
🔒 Locked

SDL keyoard input question

Started by kRogue Mar 18, 2005 at 12:27 AM 1 replies 700+ views
Original Post
kRogue
kRogue
Hi all, I am using SDL to read the keyboard... now sometimes I want the user to be able to "type" in stuff... so if they hold shift and press 'a' I want to get 'A' .... is there a simple function where I can convert an SDL-keyevent to an ASCII-code character (I know some info gets lost).... I imagine that it may also be quasi-dependent on what keyboard some is using (namely on US keyboards shift-7 is &, but on, say FIN keyboards shift-7 is /) Best Regards
Close this Gamedev account, I have outgrown Gamedev.
Drew_Benton
Drew_Benton
Yeap [smile]. Take a look at this post for the code and this post for the explanation. Feel free to PM me about questions about the code or post if you decide to use this method. There are quite a few little thing you can do to make this how you want. I have one more post that shows how to do what you are describing - in terms of sving it to a string here.
kRogue
kRogue
HI,

thanks for the advice, the key element that I needed is really:

//enable UNICODE deciphering.SDL_EnableUNICODE(1);


after that, really all that one needs to do is this:

char ch;if ( (key.unicode & 0xFF80) == 0 && isprint(ch=key.unicode & 0x7F) )	 {	   ch = key.unicode & 0x7F;           //play with ch          }


(atleast to extract ascii printable character), the inernational characters I am NOT going to deal with... though I proably should one day... I think that allocating 64KB worth of booleans (or 8KB worth of bitfields) is actually a bad idea to deal with unicoded characters... rather, like SDL docs advise, if going into a "GAME" mode, do
SDL_EnableUNICODE(0); SDL_EnableKeyRepeat(0,0);

and when going into a "GUI" mode do
SDL_EnableUNICODE(1);SDL_EnableKeyRepeat(delay,interval);


this is what I am doing now [this is for a game GUI system I am building, and I wanted to make a text input window thingy] so basicly all I do is when the text input gets the focus I enable UNICODE and repeat keys, and when it loses the focus I disable UNICODE and repeat keys...

Best Regards
Close this Gamedev account, I have outgrown Gamedev.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.