Pressing multiple keys at the same time using Glut

I am programming a game and I need to be able to have multiple keys pressed simultaneously activating their respective functions continuously as long as the key is pressed. I also need to use shift and control keys. Is there a way to do this using glut commands? If not, can someone direct me to nonglut code that will do this for me?

Here is an example of how my keyboard functions currently look -

void keypressSpecial (int key, int x, int y)
{
if (key== GLUT_KEY_UP){
cout<<“up”<<endl;
}

if (key== GLUT_KEY_DOWN){
	cout&lt;&lt;"down"&lt;&lt;endl;
}

}

void keypressNormal (unsigned char key, int x, int y)
{
if (key==109){ //m
cout<<"test m "<<endl;
}
}

And here is how I call them in main –
glutSpecialFunc(keypressSpecial);
glutKeyboardFunc(keypressNormal);

Whenever I switch press a new key, it stops doing what the key before it did (sort of like having to take your feet off the gas pedal whenever you turn the wheel).
I also don’t understand how to use glutGetModifiers to use shift and control.

Thanks ahead time

Hi !

The PC keyboard is a tricky beast, it uses a serial interface to send information to the PC, so you cannot detect all combinations of keys pressed at the same time.

You can detect Shift,Ctrl,Alt and pressing multiple aroow keys at the same time, but I don’t think it is possible with the alpha keys, but I may be wrong here.

Mikael

you can do that with glut. but only with linux.
you have to set keyboard repeat off and register the keyboard/keyboard_up and special/special_up callback.

to disable keyboard repeat, do glutSetKeyRepeat(0) and to enable it, do glutSetKeyRepeat(1).

maybe switching to SDL could be a good thing.

Originally posted by mikael_aronsson:
[b]Hi !

The PC keyboard is a tricky beast, it uses a serial interface to send information to the PC, so you cannot detect all combinations of keys pressed at the same time.

You can detect Shift,Ctrl,Alt and pressing multiple aroow keys at the same time, but I don’t think it is possible with the alpha keys, but I may be wrong here.

Mikael[/b]

OT, but do USB keyboards correct this problem (not picking up all key combos)?

You can do it with glutkeyfunc and glutkeyupfunc also in windows(I did it too:-)) but you will have to create a table of bools which will represent keys(true-pressed false-not pressed) and check it with other function

DirectInput can do this easily as well.

how do you implement directx into a glut program?

Assuming you are using GLUT under windows, implementing DirectInput should be very easy. In Linux, of course, you are out of luck.