GLUT up key problem

Started by
1 comment, last by Demolit 15 years, 1 month ago
I've been having some difficulty handling a multiple key press with the Up key held down. This is the code I have to handle it:

bool keys[256];
int UP_KEY = 128;
int LEFT_KEY = 129;
int RIGHT_KEY = 130;

void keyboardDown(unsigned char key, int x, int y)
{
    keys[(int)key] = false;
}
void keyboardUp(unsigned char key, int x, int y)
{
    keys[(int)key] = false;
}

void specialKeyboardDown(int key, int x, int y)
{
    switch (key)
    {
        case GLUT_KEY_LEFT:
            keys[LEFT_KEY] = true;
            break;
        case GLUT_KEY_RIGHT:
            keys[RIGHT_KEY] = true;
            break;
        case GLUT_KEY_UP:
            keys[UP_KEY] = true;
            break;
    }
}

void specialKeyboardUp(int key, int x, int y)
{
    switch (key)
    {
        case GLUT_KEY_LEFT:
            keys[LEFT_KEY] = false;
            break;
        case GLUT_KEY_RIGHT:
            keys[RIGHT_KEY] = false;
            break;
        case GLUT_KEY_UP:
            keys[UP_KEY] = false;
            break;
    }
}

void processKeys()
{
    if(keys[LEFT_KEY])
        cout << LEFT_KEY << endl;
    if(keys[RIGHT_KEY])
        cout << RIGHT_KEY << endl;
    if(keys[UP_KEY])
        cout << UP_KEY << endl;
    if(keys[32])
        cout << 32 << endl;
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutSpecialFunc(specialKeyboardDown);
    glutKeyboardFunc(keyboard);
    glutSpecialUpFunc(specialKeyboardUp);
    glutKeyboardUpFunc(keyboardUp);

    glutMainLoop();
}

Pretty basic. Here's the deal, this all works just fine on my computer, but when I sent it to 2 other people and they are unable to press Up and Spacebar together (but Left and Right work fine). Then I sent it to someone else, and it works fine on his computer. Is there something I'm missing which is system dependent?
Advertisement
It is, unfortunately, a hardware limitation on how keyboards are made. Depending on the maker of the keyboard, combinations that will work OK for some will not work for others.
There has to be a workaround, right?
I should probably mention, the code I gave is not the full code. The program actually worked on their computers before I added more stuff. As such, I believed it could have been a memory leak or some other fault on my part, but I checked all that and it seems ok. I switched the key from Up to 'W', and sure enough everything works fine, which proves its probably a keyboard problem.
What other reason would there be for it to suddenly stop working?

This topic is closed to new replies.

Advertisement