hi, im working on an online 2d RPG, and im tweaking the raw user input. the input im talking about here is when you type in your login name and password, etc. to do this, it looks something like this:
switch( event.type )
{
case SDL_KEYDOWN:
{
//get the key state
skey = event.key.keysym.sym;
if ((event.key.keysym.unicode & 0xFF80) == 0) //if its a unicode message
{
ch = event.key.keysym.unicode & 0x7F; //grab the character
}
}
}
now, the problem is, here tabs, enters, and other strange characters will all work, and fill my string with these values. i want to restrict it so only numbers and letters will work. so, i tried doing this:
if ((event.key.keysym.unicode & 0xFF80) == 0) //if its a unicode message
{
//if this char is a letter or a number
if((event.key.keysym.unicode >= 48 && event.key.keysym.unicode <= 57 && event.key.keysym.unicode >=65 && event.key.keysym.unicode <=90 && event.key.keysym.unicode >=97 && event.key.keysym.unicode <=122) )
{
ch = event.key.keysym.unicode & 0x7F; //grab the character
}
}
i *think* this is what im suppoed to do. i stepped through the code and the event.key.keysym.unicode value is indeed the value im thinking it is (it is mapped to an ASCII value). however, doing this method, i can type any key and none of it is accepted... now, i also tried doing this:
if ((event.key.keysym.unicode & 0xFF80) == 0) //if its a unicode message
{
ch = event.key.keysym.unicode & 0x7F; //grab the character
//if this char isnt a letter or a number, make it 0
if(!(ch >= 48 && ch <= 57 && ch >=65 && ch <=90 && ch >=97 && ch <=122) )
{
ch = 0;
}
}
but, this does the same thing. no input is accepted. does anyone know what im doing wrong? thanks for any help.