0

It's been a while since I've used Glut for keyboard input handling, but I feel as though the keyboard callback function once provided an unmodified Key parameter - I might be remembering wrong.

In other words, pressing "r" returned a lowercase "r" character, while pressing SHIFT + "r" still returned a lowercase "r" and not an uppercase "R". This isn't the case now (perhaps it never was) as using a modifier key (SHIFT, CONTROL, ALT) actually modifies the key sent to the callback function. I've been trying to find a way to get the raw, unmodified value but have since had no luck.

Is there a way of accessing the unmodified keyboard value from the callback function, or will I need to find a way to reverse the modification manually in order to get the correct key value?

glutKeyboardFunc(keyDown);

...

void Game::keyDown(unsigned char key, int mouseX, int mouseY)
{
    switch (key)
    {
    case 'r':
       {
           cout<<"Called when 'r' is pressed"<<endl;
           cout<<"Is NOT called when SHIFT is the modifier"<<endl;
           break;
       }
    case 'R':
        {
            cout<<"Called ONLY when 'r' is pressed with SHIFT"<<endl;
            cout<<"Is NOT called when 'r' is pressed on its own"<<endl;
            break;
        }
    case 18:
        {
            cout<<"Called ONLY when 'r' is pressed with CONTROL"<<endl;
            cout<<"Is NOT called when 'r' is pressed on its own"<<endl;
            break;
        }
    }
}

Any help or advice would be greatly appreciated.

4

1 回答 1

0

您正在寻找此功能:

int glutGetModifiers(void);

您可以将结果分配给整数并使用以下内容进行检查:

GLUT_ACTIVE_SHIFT
GLUT_ACTIVE_CTRL
GLUT_ACTIVE_ALT

一个小例子

int modifier = glutGetModifiers();
    if (modifier == GLUT_ACTIVE_CTRL)
        //code
    else
        //code
}

另请注意,该函数只能在处理键盘或鼠标输入事件的函数内部调用。

于 2013-09-04T20:27:13.530 回答