How can I register that the CTRL key is depressed? The following code works for all keys except CTRL:
switch (key)
{
case GLUT_KEY_RIGHT:
cout << "right key" << endl;
glutPostRedisplay(); // Redraw the scene
break;
case GLUT_KEY_LEFT:
cout << "left key" << endl;
glutPostRedisplay(); // Redraw the scene
break;
case GLUT_KEY_UP:
cout << "up key" << endl;
glutPostRedisplay(); // Redraw the scene
break;
case GLUT_KEY_DOWN:
cout << "down key" << endl;
glutPostRedisplay(); // Redraw the scene
break;
case GLUT_ACTIVE_CTRL:
cout << "CTRL pressed" << endl;
glutPostRedisplay(); // Redraw the scene
break;
}
GLUT cannot detect just the press of Ctrl . This fact is also hinted at by the fact that the "enumerator" for Ctrl is not GLUT_ KEY _CTRL, but GLUT_ ACTIVE _CTRL.
However, you can query the state of Ctrl
when another key is pressed:
case GLUT_KEY_RIGHT:
cout << "right key";
if (glutGetModifiers() & GLUT_ACTIVE_CTRL)
cout << " w/Ctrl";
cout << endl;
glutPostRedisplay(); // Redraw the scene
break;
See the documentation of glutGetModifiers()
for more details.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.