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).]
system
December 28, 2000, 9:42pm
2
I do not think that you can use more than one key at the same time with GLUT. Use DirectInput instead.
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
December 29, 2000, 1:07pm
4
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