How would I detect if any letter key is pressed. Would I have to use GetAsyncKeyState() for every letter key? Or could I have some kind of loop going through all the hexadecimal values for every letter? I don't know how I would go through hexadecimal values with a loop.
some kind of loop going through all the hexadecimal values for every letter
Either way, you're going to be doing what you set out to do; detect keys pressed.
Response question:
What keys are you specifically detecting?
Certainly not all of the keys are of value, unless you're creating a key pressed detection program.
Else, stick with the keys you're listening for.
Tip:
Hex values and integer values are interchangeable; you can detect using integer representation.
http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
0xFE is the last value, and has an integer value of 254.
Looping on GetAsyncKeyState is possible, but is not necessary.
If you are using an actual window, it's much easier to just capture the WM_KEYDOWN message which is sent to your window whenever the user presses any key. Then you can check the key they pressed, and it's in a letter, do whatever you want.
Practically all game libs (like SFML, SDL, Allegro) have similar functionality where they send events when a key is pressed.
Same with widgetry libs -- they also have the same thing (Qt, wxWidgets)
I only want to detect letters A-Z. I tried this code, but it didn't work. Are these the right integer values for it? Also, I'm not using a window for this so I can't do Allegro stuff.
1 2 3 4 5 6 7 8 9 10
int numKeys = 0;
for (int i = 203; i <= 228; i++) {
if(GetAsyncKeyState(i))
numKeys++;
}
if (numKeys > 0) {
stuff
}