• 15
• 15
• 11
• 9
• 10

'a' - SDLK_a

This topic is 4865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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

Share on other sites
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...

Share on other sites
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.