Sign in to follow this  

Glut Key input And Multiple keys

This topic is 2443 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
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
Sorry for drudging up ancient threads but anyone else looking to accept multiple key inputs should check out this tut: [url="http://www.swiftless.com/tutorials/opengl/keyboard.html"]http://www.swiftless...l/keyboard.html[/url]

This guys whole tutorial series is ace.

Share this post


Link to post
Share on other sites

This topic is 2443 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this