Jump to content
  • Advertisement
Sign in to follow this  
dnaxx

GLUT Keyboard problems

This topic is 4846 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

Hello, I want to navigate through my landscape with the up, down, left and right-keys. When I hold the up key pressed, I move forward. To move left, I press the left key and without leaving the up key. now I move one step left and then I stop. In games it is possible to go e.g. one step left while holding the up key and the going further without the need of repressing the up-key. I hope my description is understandable ;). How can this be achieved? Thanks,

Share this post


Link to post
Share on other sites
Advertisement
Pretty similar to my problem I just posted.

http://www.gamedev.net/community/forums/topic.asp?topic_id=338511

I need to know this also :p

Thx

Share this post


Link to post
Share on other sites
that's another issue but with a timing function, it should not be a problem.

regarding my problem: I fixed it with a array, which holds the values of pressed keys.

Share this post


Link to post
Share on other sites
it's very simple.


bool pressed_keys[255];

void init()
{
for (i=0; i<255; i++) pressed_keys = false;
}


void glutSpecialKeypressfunction(int key, x, y)
{
pressed_keys[key] = true;
}

void glutSpecialKeypressUpfunction(int key, x, y)
{
pressed_keys[key] = false;
}


glutRenderfunction()
{
if (pressed_keys[GLUT_UP_KEY]) moveforward;
if (pressed_keys[GLUT_LEFT_KEY]) moveleft;
...

}



for the glutKeyboard function use (int)key instead of key (because key is a unsigned char.

that's it ;).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!