如何记录 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;
}
最佳答案
GLUT 无法检测到仅按下Ctrl。 Ctrl 的“枚举器”不是 GLUT_KEY_CTRL,而是 GLUT_ACTIVE_CTRL,这一事实也暗示了这一事实。 p>
但是,您可以查询按下另一个键时 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()
了解更多详情。
关于c++ - OpenGL 和 GLUT 键盘功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21635367/