Thanks for the reply. Your output values gave me some ideas. By purely empirical means, the following code seems to be working:
Code:
unsigned int sc = MapVirtualKey(vk, 0);
// Is vk ASCII?
char buf[256];
memset(buf, 0, 256);
unsigned short int temp;
bool asc = (vk <= 32);
if (!asc && vk != VK_DIVIDE)
asc = ToAscii(vk, sc, buf, &temp, 1);
// Set bits
sc <<= 16;
sc |= 0x1 << 25; // <- don't care
if (!asc) sc |= 0x1 << 24; // <- extended bit
// Convert to ANSI string
if (GetKeyNameTextA(sc, buf, 256) > 0)
rslt = buf;
Although I haven't fully tested it with every possible key value. Also I can't say I fully understand it. It seems I should only set bit 24 if the VK is not ASCII. So if there is a better way to do this, please let me know anyone.
Thanks again jverkoey.