PDA

View Full Version : Pressing multiple keys at the same time using Glut



08-05-2003, 06:58 PM
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.

Thanks ahead time http://www.opengl.org/discussion_boards/ubb/wink.gif

mikael_aronsson
08-05-2003, 09:15 PM
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

errno
08-05-2003, 10:47 PM
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.

Jared@ETC
08-06-2003, 03:31 AM
Originally posted by mikael_aronsson:
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

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

Vlasko
08-07-2003, 06:11 AM
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

Jared@ETC
08-07-2003, 06:48 AM
DirectInput can do this easily as well.

Vlasko
08-08-2003, 06:13 AM
how do you implement directx into a glut program?

Jared@ETC
08-08-2003, 09:59 AM
Assuming you are using GLUT under windows, implementing DirectInput should be very easy. In Linux, of course, you are out of luck.