Jump to content
  • Advertisement
Sign in to follow this  
thedustbustr

'a' - SDLK_a

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

If you intended to correct an error in the post then please contact us.

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 this post


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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!