PDA

View Full Version : Keyboard input



12-22-2003, 06:48 PM
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?

mikael_aronsson
12-23-2003, 12:25 AM
Hi !

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.

Mikael

marcus256
12-25-2003, 11:00 PM
You can register all keypresses in your keyboard function, and put them in an array (say char keys[256]), 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).