0

Can someone give me an example of how to use the ToAscii functions to convers windows virtual key codes to ascii characters? I've tried to search on google, but I can't find an example..

3
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
0

Okay, I converted it to C but when I run it and press shift, it doesn't give me any characters, even after i lift the shift key up..

char MapKey(int key)
{
	char *result;
	int c;
	byte ks[256];

	GetKeyboardState(ks);
	result = malloc(3);
	result[0] = 0;

	c = ToAscii(key, MapVirtualKey(key,0), ks, &result[0], 0);

	if(c == 1)
	{
		c = result[0];
		free(result);
		return c;
	}

	free(result);
	return 0;
}
0

The shift key shows no output, by itself, so it has no ASCII code value. If the shift key is depressed, the OTHER keys will have a different ASCII value, but the shift key itself, doesn't need one.

There is a "shift in" and "shift out" at ASCII 14 and 15, but that is legacy stuff from telegraph days, iirc.

0

why is that program using malloc() to allocate just 3 bytes??? It seems such a waste of CPU cycles. Just declare it like this: char result[3]; then remove the malloc() and free()

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.