Beakie Beakie - 1 year ago 125
C++ Question

glut - holding a key down

I have some basic code to collect key up and key down events using glut.

If I hold a key down I am getting continuous events firing (down/up/down/up/down/up/........), instead of the intended down (once, at the start) and up (once, at the end)

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

void keyDown (unsigned char key, int x, int y)
std::cout << "keydown " << key << "\n";

void keyUp (unsigned char key, int x, int y)
std::cout << "keyup " << key << "\n";

void render(void)
std::cout << "render\n";

int main(int argc, char** argv)
glutInit(&argc, argv);
glutInitWindowSize(300, 300);
glutInitWindowPosition(100, 100);
glutCreateWindow("Hello world :D");

return 0;

Any input appreciated.

Answer Source

Your problem is that the auto repeat key is on. To turn it off, just put, at your initialization phase this command:


Man page at:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download