by Photon
It is often the case in games, that keyboard input is needed to input text, rather than be used for usual game controls. This poses three basic problems:
To solve this problem, we can use various Win32 API calls to resolve which ASCII code the key should be translated to. These are the steps we'll use:
Here's a sample function: static int scan2ascii(DWORD scancode, ushort* result) { static HKL layout=GetKeyboardLayout(0); static uchar State[256]; if (GetKeyboardState(State)==FALSE) return 0; UINT vk=MapVirtualKeyEx(scancode,1,layout); return ToAsciiEx(vk,scancode,State,result,0,layout); } This returns the number of characters extracted. It will return 0 in the case that there was no conversion, or 1 or 2, depending multibyte character sets, for a valid output. In most cases, using char(result[0]) would provide the desired output. Discuss this article in the forums
See Also: © 1999-2011 Gamedev.net. All rights reserved. Terms of Use Privacy Policy
|