View Full Version : Multi Keyboard inputs & GLUT

10-04-2000, 07:57 AM
I am using Ansi c under win 98 in VC++ (6). I have created a little game using glut where 2 ship shoot at each other. My problem is I want to ba able to hold down say 4 keys at once and be able to detect them (so that I can shoot, turn and accelerate at once). Glut only allows me to do 1 at a time. Does any one know a way around this before I go off and try and figure it out?

Thanks heaps
Jason http://www.opengl.org/discussion_boards/ubb/wink.gif

10-04-2000, 08:21 AM
The method is to use a buffer and then check later if the key are pressed.

bool buffer[256];

void keyboard(int key, int x, int y )
buffer[key] = true;

this the keyboard function

Now every frame or everytime you want to update your gameworld, you just check wich keys are down using the buffer and work accordingly.

10-04-2000, 09:10 AM
The other part of that one is

void keyboardUp( int key, int x, int y )
buffer[key] = false;

and register it with glut as glutKeyboardUpFunc( keyboardUp ).

that should help solve the problem.

Note that you'll probably need to use glutSpecialFunc() and glutSpecialUpFunc() if you want to use arrow keys, function keys, etc.

10-04-2000, 05:33 PM
I will give it a go.
Thanks for the quick and helpful response.

10-04-2000, 07:41 PM
oups, that was dumb of me to forget that! Thanks phlake!

10-05-2000, 06:59 AM
Worked perfectly, as if i doubted you! http://www.opengl.org/discussion_boards/ubb/wink.gif

Thank you very much!
Jason http://www.opengl.org/discussion_boards/ubb/biggrin.gif http://www.opengl.org/discussion_boards/ubb/biggrin.gif (big fat meaty smile)