View Full Version : Are there any KeyUp/KeyDown type functions in GLUT?

03-15-2002, 09:06 PM
I'm new to OpenGL (just started using a week ago at university). So far I've managed to get a cube up and can rotate it using keypresses, however it's only using the glutKeyboardFunc() command. Is there a way to implement a KeyUp/KeyDown type function which will allow the cube to rotate when the key is pressed and then stop moving when the key is released. This would be without using Windows messages as I have to use it under Linux at university.

Any help would be appreciated.

Note: posted this before but the name screwed it up somehow :P

03-15-2002, 09:35 PM
keep track of whether a key is up or down yourself
eg pseudo code


if (key[X]==PUSHED) blah

03-15-2002, 11:19 PM
Don't use glut's functions ! They're unable to understand that one might press *two* keys at the same time. If you're under win32,
just use GetAsyncKeyState !


03-16-2002, 03:25 AM
But the answer is yes

03-16-2002, 04:41 AM
OK thanks, but I still can't get this to run.

I'm trying: glutKeyboardUp(asciiKeyUp); assuming that it's the same as the keypress function: glutKeyboardFunc(asciiKey);

Sorry if I'm way off but I'm still new to this.

03-16-2002, 05:19 AM
void keyboard_up(unsigned char key, int x, int y);


03-16-2002, 01:11 PM
Thanks heaps for the help. Everything's running fine now http://www.opengl.org/discussion_boards/ubb/smile.gif

03-16-2002, 04:32 PM
>>Don't use glut's functions ! They're unable to understand that one might press *two* keys at the same time.<<

?? yes glut can understand if u push 2 or more keys at the same time

03-17-2002, 05:32 AM
Do the experience by yourself if you don't believe me ! LGLUT uses standard windows message (in its windows implementation). The same messages that are used for any text typing under windows. Click on "post reply", go to any text-edit box, like "Your Reply", and maintain 2 keys pressed. Here's what I obtain :


you see, only one key is repeated !
To work around this problem, you have to use another way of reading keyboard input. GetAsyncKeyState is one.


03-17-2002, 08:57 AM
do a demo in glut (as thats the api in question) yourself + see if it can recoginize 2 keypresses, u will find it can


in answer to your question both h + j were printed, check my first post above + u will see that this confirms that the standard windows messages as well as glut can handle 2 key presses at once. u disproved yourself http://www.opengl.org/discussion_boards/ubb/smile.gif
btw u can dusable keyrepeats in glut (check the man pages for the command)

03-18-2002, 05:29 AM

Your example is what is shown in a text editor, in other words how the text editor interprets the Windows events -> not relevant!

The GLFW api also uses standard Windows events to track key up/down events. Once a key down event is received, it is recorded in a keyboard table. Checking for the key with glfwGetKey() returns true until a key up event is received, regardless if any other keys were pressed in between. Also, checking for the value of a C/C++ array element is probably much faster than using a Windows function.

03-18-2002, 07:57 AM
OOoook I've understood : so far, I had not made use of glutKeyboardUp. I should have read Gavin's post more carefully ! http://www.opengl.org/discussion_boards/ubb/redface.gif