🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
Multiple Key Presses
int ASCIIKeys[256];
int SpecialKeys[256]; // keys like up down..
void AsciiKeyPressed(unsigned char key)
{ ASCIIKeys[key]=1;
}
void AsciiKeyReleased(unsigned char key)
{ ASCIIKeys[key]=0;
}
void SpecialKeyPressed(unsigned int key)
{ SpecialKeys[key]=1;
}
void SpecialKeyReleased(unsigned int key)
{ SpecialKeys[key]=0;
}
in your gameloop you now have to do the following:
...
if(SpecialKeys[FIRE]) player.firegun();
if(SpecialKeys[UP]) player.run();
...
The only problem you now have is to make your programm call the callback functions from above when a keyboard event happens.
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
and then...
if (KEY_DOWN(VK_RETURN))
{
// return pressed
}