Malcolm McLean
8/21/2011 1:45:00 PM
On Aug 21, 12:06 pm, lo...@live.nl wrote:
> Hello comp.lang.c!
>
> I'am trying to convert a virtual key to a normal character (just a
> human readable character). This is my code:
>
> LPWORD r;
> SHORT c = /* Some virtual key */
> byte ba[256];
>
> r = calloc(3, sizeof(char));
>
> /* Init keybord status */
> if (GetKeyboardState(ba) == 0)
> {
> printf("ERROR: Could not get keybord status.");
> exit(1);
>
> }
>
> ToAscii(c, MapVirtualKey(c, 0), ba, r, 0);
>
> putc(r[0]);
>
> This code works. BUT not 100% hehe, when holding the shift key the
> ToAscii function still returns the 'normal' characters, for example
> lower case characters instead of uppercase, [ instead of {, etc.
>
The function is too low-level.
<OT>
Windows sends a WM_CHAR message to a window that receives a
character from a keyboard or similar device attached to it. Normally
this is the message you want to trap for everyday text input.
</OT>