문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top