Problem with glutKeyboardUpFunc

im having problems with glutKeyboardUpFunc, i’ve registered a keyboard function that saves the when the keys are pressed and the keyboard up function releases the keys by setting their corresponding value to 0, but im having a problem when you press say first the ‘w’ buttom to move forward and then you want to turn right a bit by pressing ‘d’ then releasing it with the ‘w’ key still down this will automatically call the keyboardup function with ‘w’ then with ‘d’ hence turning off the ‘w’ character when in reality is still down, i cant see a way to fix this problem and it is really annoying,
“note the functionality is handled with a timer function”

I certainly don’t see this problem. Here’s simple test program. If I hold ‘a’ then hold a sequence of other keys I only ever get an Key UP event when I release the key.


#include <iostream>
#include <GL/glut.h>

void display(void)
{
}

void reshape (int w, int h)
{
    glViewport (0, 0, (GLsizei) w, (GLsizei) h);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    gluPerspective( 90,1.0,0.1,100 );
    glMatrixMode (GL_MODELVIEW);
}

void keyboard(unsigned char key, int x, int y)
{
   switch (key) {
      case 27: exit(0); break;
      default: std::cout << "KEY DOWN = " << key << "
"; break;
   }
}

void keyboardUp(unsigned char key, int x, int y)
{
   std::cout << "KEY UP = " << key << "
";
}

static void processMouseButton(int button, int state, int mouseX, int mouseY)
{
}


static void processMouseActiveMotion(int x, int y)
{
}

static void processMousePassiveMotion(int x, int y)
{
}

static void processMouseEntry(int state)
{
}


int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glEnable(GL_DEPTH_TEST);
    glutInitWindowSize (400, 400);
    glutCreateWindow("TEST");

    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutReshapeFunc(reshape);
    glutKeyboardFunc(keyboard);
    glutKeyboardUpFunc(keyboardUp);

    glutMouseFunc(processMouseButton);
    glutMotionFunc(processMouseActiveMotion);
    glutPassiveMotionFunc(processMousePassiveMotion);
    glutEntryFunc(processMouseEntry);

    glutMainLoop();
    return 0;
}

BTW I’m running on XP and compiling under cygwin.