[SDL] Reading text from keyboard

Glenn Maynard g_sdl at zewt.org
Tue Jan 21 20:06:03 PST 2003


On Wed, Jan 22, 2003 at 04:31:39AM +0100, Daniel Phillips wrote:
> > 				if((Event.key.keysym.unicode & 0xFF80) == 0)
> > 				{
> > 					char ch = Event.key.keysym.unicode & 0x7F;
> > 					if(ch)
> > 						m_strText += ch;
> > 				}
> > 		}
> > 	}
> >
> > The problem is that the variable ch is always zero whatever key I press. Do
> > you have any idea what I'm doing wrong? (I've got WinXP)
> 
> Try making ch (unsigned) instead of (char).

He's only looking at characters that don't have any bits above 7 set.
if((Event.key.keysym.unicode & 0xFF80) == 0) is a slightly obfuscated
version of if((Event.key.keysym.unicode < 0x80).

I'm guessing he was just trying to get ASCII working with Unicode
enabled before worrying about other Unicode values; I believe I suggested
(or at least meant to suggest) he look at the Event.key.keysym.unicode
value directly (in a debugger).

-- 
Glenn Maynard




More information about the SDL mailing list