Jump to content
  • Advertisement
Sign in to follow this  
thedustbustr

'a' - SDLK_a

This topic is 5052 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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!