如何注册CTRL键被按下?以下代码适用于除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;
}
答案 0 :(得分:4)
GLUT无法检测只是按 Ctrl 。 Ctrl 的“枚举器”不是GLUT_ KEY _CTRL,而是GLUT_ ACTIVE _CTRL。
但是,当按下另一个键时,您可以查询Ctrl
的状态:
case GLUT_KEY_RIGHT:
cout << "right key";
if (glutGetModifiers() & GLUT_ACTIVE_CTRL)
cout << " w/Ctrl";
cout << endl;
glutPostRedisplay(); // Redraw the scene
break;
有关详细信息,请参阅documentation of glutGetModifiers()
。