'a' - SDLK_a

Started by
1 comment, last by TANSTAAFL 19 years, 4 months ago
Is there a way to convert from char values into SDLK keycodes (in SDL of course), or I have to specialcase each code? If it matters, I'm actually storing each key as a std::string.

char key='a';
SDLKey keycode;
if (key=='a') keycode=SDLK_a;
else if (key=='b') keycode=SDLK_b;
etc. Thanks
Advertisement
You can probably assume they're in order. Check to make sure though. Then you could do:

if (key >= 'a' && key <= 'z') keycode = SDLK_a + (key - 'a');

and so on...
“[The clergy] believe that any portion of power confided to me, will be exerted in opposition to their schemes. And they believe rightly: for I have sworn upon the altar of God, eternal hostility against every form of tyranny over the mind of man” - Thomas Jefferson
the SDLK_* constants were made to correspond as closely as possible with the ASCII values they represent whenever they could. Check out SDL_keysym.h. If the value is less than 128, then the value is the ASCII value and needs no translation.

Get off my lawn!

This topic is closed to new replies.

Advertisement