| Jason Rangle 2006-01-24, 7:07 pm |
| I have been fighting with these two functions forever. I can't seem to get
it right. Here is what I have:
#include <windows.h>
#include <stdio.h>
int main()
{
int nAllKeys[256], i, RetMapVkey;
BYTE bKeyBuf[256];
WORD lpWord;
char ch;
for(i=0;i<256;i++)
{
nAllKeys[i] = i;
}
while(TRUE)
{
for(i=0;i<256;i++)
{
if(GetAsyncKeyState(nAllKeys[i]) == -32767)
{
GetKeyboardState( bKeyBuf );
RetMapVkey = MapVirtualKey(nAllKeys[i],0);
ToAscii(nAllKeys[i], RetMapVkey, bKeyBuf, &lpWord, 0);
ch = (char) lpWord;
printf("%c\r\n", ch);
}
}
}
return 0;
}
When I only have:
#include <windows.h>
#include <stdio.h>
int main()
{
int RetMapVkey;
BYTE bKeyBuf[256];
WORD lpWord;
char ch;
GetKeyboardState( bKeyBuf );
RetMapVkey = MapVirtualKey(0x41,0);
ToAscii(0x41, RetMapVkey, bKeyBuf, &lpWord, 0);
ch = (char) lpWord;
printf("%c\r\n", ch);
return 0;
}
I can hold down the shift key, execute my program and it will spit out 'A'
and will spit out 'a' when shift is not pressed... which is expected. For
some reason when I loop through all the virtual-keys, grab one that is
pressed then call GetKeyboardState() it doesn't work correctly. I have been
at this forever and I give up. Can someone please guide a lost soul?
--Jason
|