Jump to content
  • Advertisement
Sign in to follow this  
AverageJoeSSU

Glut Key input And Multiple keys

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

i have searched online, and noticed that the common structure is a switch statement with the key ascii or kind of key, a case, and then code. However, this structure seems to not lend itself for when multiple keys are being held down. i was thinking about using if statements in my cases... but it seems like only one key can be pressed at a time (because only one is passed into the switch)?? im using GLUT. my structure is like void keyboard(unsigned char p_key, int p_x, int p_y) { switch (p_key) { case 'j': case 'J': ObjTranslate(&object[obj_control],0,0,-1); break; case 'm': case 'M': ObjTranslate(&object[obj_control],0,0,1); break; case 'k': case 'K': ObjRotate(&object[obj_control],0,20,0); break; case 'l': case 'L': ObjRotate(&object[obj_control],0,-20,0); break; case 'w': case 'W': ObjRotate(&object[obj_control],20,0,0); break; Thanks for the help?

Share this post


Link to post
Share on other sites
Advertisement
To handle multiple keys you need to separate game logic from keyboard handling code. Make an array of the entire keyboard state and update this array using the keyboard function. Game logic will then access this array and make decisions based on whatever keys were pressed or released.

For details, see these links:
http://www.robthebloke.org/opengl_programming.html
http://courses.dsu.edu/csc433/notes/notes4.htm
http://www.zeuscmd.com/tutorials/glut/02-KeyboardInput.php

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!