Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Slayer-X

Multiple Key Presses

This topic is 6935 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Perhaps this will help you:
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.

Share this post


Link to post
Share on other sites
if you are using windows:

#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
}

Share this post


Link to post
Share on other sites
How do you get multiple key presses and process them in your game? Example: Getting the forward key being presses and the fire key being pressed and making the player fire and walk at the same time.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!