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<<"down"<<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.
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.
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).
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