Jump to content
  • Advertisement

Archived

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

mars_888

Converting keycodes/scancodes into ascii?

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

Advertisement
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;
else
usecaps = false;

//forgot dik value for a
if (keystate[key] 0x80) {
if (usecaps)
keychar = "A";
else
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"


http://members.xoom.com/myBollux

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!