View Full Version : Keyboard input
I'm making a racing game, using C++ and GLUT. I've got two cars, but I can only make one car go at a time. What do i need to do to fix this?
12-22-2003, 11:25 PM
The normal keyboard mode on a PC can only keep track of one a few keys pressed at the same time.
You can read more keys at the same time with some miessing around, but I don't think you can do it with GLUT only, I mean if you want to stay platform independent.
12-25-2003, 10:00 PM
You can register all keypresses in your keyboard function, and put them in an array (say char keys), where each array element is zero if the key is not pressed, or one if the key is pressed. Note that you have to handle character cases etc, since GLUT reports keys that are affected by modifiers, such as SHIFT.
Then, in your idle or display function (wherever you put your main code), you can check the state of individual keyboard keys.
A side note: GLFW (http://hem.passagen.se/opengl/glfw) does this for you (there is a function glfwGetKey(), for instance).
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.