Before I begin...
1 2 3 4 5
|
if(GetAsyncKeyState(VK_ESCAPE)) // <- this is wrong
{}
if(GetAsyncKeyState(VK_ESCAPE) & 0x8000) // <- this is right
{}
|
Bit 15 is the only bit you are interested in (assuming you want the realtime state of the key). Other bits mean other things and may give you false positives if they are set. Use the & operator to isolate the interesting bit.
As for your actual problem:
With the code below I can only read 2 keys at once. Pressing a third key is ignored |
This is not a problem with your code. It's a hardware limitation of your keyboard.
Most keyboards (especially low-end ones) are designed for typing. When people type, they typically do not press more than 1 key at a time.
Gaming keyboards typically allow more keys to be pressed simultaneously, but they are usually much more expensive, and not many people have them.
There is nothing you can do to solve this problem. It's hardware issue. You have 2 options:
1) Get a better keyboard
2) Redesign your program so that it doesn't require multiple keys to be pressed at once.
#2 is the better solution, because if you are having this problem... then other people are going to have it as well. So unless you only want your program to be usable for people who have really high-end keyboards, you don't want to use solution #1.
EDIT:
On an unrelated note. Using WinAPI to make a game is wretched. Consider getting a lib like SFML. Aside from having better performance, it's also easier to program and will be more portable.