[SDL] Reading text from keyboard

Glenn Maynard g_sdl at zewt.org
Sat Jan 18 02:06:01 PST 2003


On Sat, Jan 18, 2003 at 06:55:50AM +0000, Matt Monson wrote:
> dang, man, you're making this waaaay more hard than it has to be... this is 
> what i use....
> 
> 	// i'm using c type strings (char vectors) so my code is kinda 
> 	complex
> 	if(strlen(saying) < MAX_LEN)
> 		saying[strlen(saying)] = (char)event.key.keysym.unicode;
> 
> 	// it looks like you could just do
> 	m_strText += (char)event.key.keysym.unicode;
> }
> }

Err?  He's not overcomplicating anything; your code is incorrect.  You can't
blindly cast 16-bit Unicode values to a (typically) 8-bit char; if the
value is above ASCII (ISO-8859-1, actually: U+00FF), you'll get garbage.
It'd be more straightforward for him to write
"Event.key.keysym.unicode < 0x80", though.

Milo (please set your real name in your From line, so we don't have
to search for it), back up a bit: see if you're getting any non-zero
values in keysym.unicode.

-- 
Glenn Maynard




More information about the SDL mailing list