Advertisement

Converting keycodes/scancodes into ascii?

Started by February 15, 2001 04:49 AM
3 comments, last by mars_888 24 years ago
This might be a silly question but how do I convert a Windows Keycode/Scancode into it''s ASCII equivalent?
Prosser: But the plans were on display.Arthur Dent: On display? I eventually had to go down to the cellar.Prosser: That's the display department.Arthur Dent: With a torch.Prosser: The lights had probably gone.Arthur Dent: So had the stairs.Prosser: But you did see the notice, didn't you?Arthur Dent: Oh, yes. It was on display in the bottom of a locked filing cabinet stuck in a disused lavatory with a sign outside the door saying "Beware of the Leopard." Ever thought of going into advertising?
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...
Advertisement
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
Prosser: But the plans were on display.Arthur Dent: On display? I eventually had to go down to the cellar.Prosser: That's the display department.Arthur Dent: With a torch.Prosser: The lights had probably gone.Arthur Dent: So had the stairs.Prosser: But you did see the notice, didn't you?Arthur Dent: Oh, yes. It was on display in the bottom of a locked filing cabinet stuck in a disused lavatory with a sign outside the door saying "Beware of the Leopard." Ever thought of going into advertising?
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
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

This topic is closed to new replies.

Advertisement