PDA

View Full Version : Glut: More than 1 key at the same time



Spaceman
12-28-2000, 04:14 PM
Hello.

How can i use more than one key at the same time with Glut?




switch (key)
{
case 'q':
x++;
glutPostRedisplay();
break;

case 'a':
y++;
glutPostRedisplay();
break;

default:
break;
}


What should i change that i can use the 'q' and 'a' keys at the same time?

[This message has been edited by Spaceman (edited 12-28-2000).]

12-28-2000, 10:42 PM
I do not think that you can use more than one key at the same time with GLUT. Use DirectInput instead.

softland_gh
12-29-2000, 12:51 AM
If you mean that you want to check if 'a' and 'q' are pressed together, then you should implement this by yourself, because Glut only reports the key that have just been pressed or released. This is done by maintaining some variables that keeps the state of every key:

// Key states

int aState;
int qState;
.
.
.

// The following functions should be registered with GLUT

void Keyboard(char key, int State) {

// Maintaining key state

switch (key) {
case 'q': qState = State; break;
case 'a': aState = State; break
.
.
.
default: break;
}
}

void idle(void) {

// Processing in the background

if ((aState=GLUT_KEY_DOWN)&&(qState=GLUT_KEY_DOWN)) {
doSomething
}
.
.
.
}


[This message has been edited by softland_gh (edited 12-29-2000).]

zed
12-29-2000, 02:07 PM
its possible to have more than one ley at a time. though with some keyboards certain keys togethjer dont register.

as softland_gh said
use glutIgnoreKeyRepeat

then use glutKeyboardFunc coupled with glutKeyboardUpFunc to maintain a list of the keys currently pressed