Advertisement Jump to content


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


Converting keycodes/scancodes into ascii?

This topic is 6544 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''ve found a tutorial on the Gamedev side. Here''s the code.
dwScancode - This is your scancode. (e.g. from DirectX)
iResult - The ASCII-code.

short ConvertScancodeToASCII(DWORD dwScancode, USHORT *iResult)
{ // begin ConvertScancodeToASCII()
static HKL Layout = GetKeyboardLayout(0);
static UCHAR byState[256];

if(GetKeyboardState(byState) == FALSE)
return 0;
UINT vk = MapVirtualKeyEx(dwScancode, 1, Layout);
return ToAsciiEx(vk, dwScancode, byState, iResult, 0, Layout);
} // end ConvertScancodeToASCII()

I think that''s easy to understand...

Share this post

Link to post
Share on other sites
I just spend whole afternoon on it, but I just can''t get it to work

If I press a letter I get a capital even if I don''t press shift. And if I press other keys like symbols or numbers I get even weirder stuff

Share this post

Link to post
Share on other sites
This is slow but you can use directx to get the keystate then do something like this.

if (keystate[DIK_SHIFT] & 0x80)
usecaps = true;
usecaps = false;

//forgot dik value for a
if (keystate[key] 0x80) {
if (usecaps)
keychar = "A";
keychar = "a";

Edited by - Hunter-Killer on February 15, 2001 10:38:13 AM

Share this post

Link to post
Share on other sites
try this ''under windows''

short result = GetAsyncKeyState(VK_SHIFT);
if (result&0x10000000) shiftkey is pressed

result = GetAsyncKeyState( 65 ); // ascii value for a

thus if shiftkey is press and a is pressed then its "A" else if a key and no shift key its "a"

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!