Here is code you can use to change a character to lower case so you don't have to check for both cases all the time.
inline int ToLower( int ch )
{
const int diff = 'a' - 'A';
if( ( ch >= 'A' ) && ( ch <= 'Z' ) )
ch += diff;
return ch;
}
This function exists in the standard C run-time library but I wanted you to see what it does so you can be encouraged to use it in future. I changed the name so it can co-exist in case you want to use this. One can make a similar function for toupper.
inline int ToUpper( int ch )
{
const int diff = 'a' - 'A';
if( ( ch >= 'a' ) && ( ch <= 'z' ) )
ch -= diff;
return ch;
}
They rely on the fact that the ASCII code for the characters of the two cases are parallel and a certain number of places apart - the
diff
value.
With that, you could use a function like this :
int GetWASDvalue( int input )
{
int chlow = ToLower( input );
switch( chlow )
{
case 'a' : return VK_LEFT;
case 'w' : return VK_UP;
case 'd' : return VK_RIGHT;
case 's' : return VK_DOWN;
}
return 0; }
You can feed this function an input character and it will give you a direction.