Jump to content

  • Log In with Google      Sign In   
  • Create Account


GLUT up key problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Demolit   Members   -  Reputation: 122

Like
0Likes
Like

Posted 24 February 2009 - 04:45 PM

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?

Sponsor:

#2 Codeka   Members   -  Reputation: 1157

Like
0Likes
Like

Posted 24 February 2009 - 05:12 PM

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.

#3 Demolit   Members   -  Reputation: 122

Like
0Likes
Like

Posted 24 February 2009 - 05:21 PM

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?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS