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?

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

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 does this for you (there is a function glfwGetKey(), for instance).