SDLKey to ASCII without unicode support?
Hello,
What's the best way to convert an SDLKey to it's corresponding ASCII value without unicode support? I don't want unicode support because I don't need it, so I'd rather not suffer with the overhead.
Basically I'm writing a game console for my game, I catch the key presses (when the console is active) and print the keys,
Code:
int consoleKey(SDLKey sym)
{
char c;
static size_t i = 0;
if(sym == SDLK_RETURN)
{
strcpy(lines[0], current);
memset(current, 0, sizeof(current));
i = 0;
return 0;
} else if(sym == SDLK_BACKSPACE) {
current[i] = '\0';
if(i > 0)
--i;
return 0;
}
/* look up the key? Look-up table or something */
/* add the key if it'll fit */
if((i + 1) < sizeof(current))
{
current[i] = c;
current[i + 1] = '\0';
++i;
}
return 0;
}
What's the best way to convert 'sym' into it's corresponding ASCII code? Perhaps
Code:
char alpha[] = "abcdefghijklmnopqrstuvwxyz";
if(sym >= SDLK_a && sym <= SDLK_z)
c = alpha[sym - SDLK_a];
But the manual said "And at last, never ever ever write your own custom ASCII conversion table." http://www.libsdl.org/cgi/docwiki.cgi/SDLKey
Or a look-up table? Since it's less code :) Sorry if I'm asking too many questions :s
I've searched and searched, the SDL_keysym struct info http://docs.mandragor.org/files/Comm...sdlkeysym.html and the web :(
[edit]
Perhaps I should only enable Unicode support when my console gets focus?
Note: I haven't really commited to any library for graphics etc, I was considering Fmod for sound, GLFW for framework and alike. Would that be a better choice than SDL?
[/edit]