-
GetKeyState()
Hello :)
Quick question:
Code:
while(1){
if(GetKeyState(VK_SHIFT)<0){ //if SHIFT pressed
cout<<"control "<<endl;
if(GetKeyState('a')<0){ //if SHIFT is still being pressed and then 'a' is pressed too
cout<<"a"<<endl;
}
}
else{ //if no keys are pressed
cout<<"No key being pressed"<<endl;
}
}
GetKeyState(VK_SHIFT) works. Some don't work (like the virtual key VK_SPACE) for some reason. To detect ENTER instead of 'a', I use GetKeyState(VK_RETURN), which works.
Is there an easy way to assign a virtual key tag to nonvirtual keys like characters, numbers, and so on?
Compiler: Dev C++
Would it understand GetKeyState('a') as being a character key press of 'a' if I compiled it with Visual C++?
I did check out the table here. I tried the codes for the capital letters, the top numbers, and the numpad, but none worked.
I checked out ASCII tables (writing decimal 97 or hex 0x61 in place of 'a'), but those didn't work either.
Thanks in advance! :D
-
Its 0x41 for key A.
Virtual Key Codes There is table. Doesn't matter it's delphi.
-
I think you should write 0X41 without quotation mark...
Give that a try...
-
You can write with quotation mark, just use capital letter 'A'.
-
I personally use this for key-strokes in Windows:
Code:
#define KEYDOWN(vkey) (GetAsyncKeyState(vkey) & 0x8000)
#define KEYUP(vkey) !KEYDOWN(vkey)
And yes, use capital letters. Lowercase ones won't do the trick.