Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


How can I convert a Virtual Key code into a ASCII Code in C++

This topic is 5235 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

I''m using Direct X, and I want to be able to emulate a gets() function. But when I get the WM_KEYDOWN message, it gives me the key pressed as a virtual key, and the char variable type stores it as an ascii code. I figure I need to convert from virtual key to ascii. If anyone knows of a better way to do this, share! Thanks

Share this post

Link to post
Share on other sites
The wParam variable in the WndProc function converts directly into the correct character.

case WM_CHAR:
// if its a letter (uppercase or lower)

if((wParam > 64 && wParam < 91) || (wParam > 96 && wParam < 123))
// Then set CurrentKeyDown to wParam

char CurrentKeyDown = wParam;
return 0;

I use DirectX 8.1 and C++ (Microsoft Visual C++ 6.0 Professional edition)

Share this post

Link to post
Share on other sites

  • 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!