multiple keystrokes and holding a key down...

If two keys are pressed down at the same time, is it possible, using glut’s callback functions (or glut in general), to respond to both keys at once? Its seems that the second key interrupts the actions produced by the first…
Also, can you eliminate the pause that occurs when the user presses and holds a key between the first time the action is performed and the subsequent constant doing of action? In other words, when I press the up key in this program, I want a cube on the screen to continuasly spin, without pausing right after the first movement. I tried setting key repeat to on (glutSetKeyRepeat( GLUT_KEY_REPEAT_ON ) :wink: but it didn’t seem to help at all…

Originally posted by quibbles:
In other words, when I press the up key in this program, I want a cube on the screen to continuasly spin, without pausing right after the first movement.
Maybe I’m not understanding you, but, are you only updating the rotation of the cube when receiving a key callback? Instead, set the rotation rate and use glutIdleFunc() to update the cube’s rotation (based upon that rotation rate) and force the cube to be redrawn using glutPostRedisplay().

Oh, sorry, I didn’t quite make it clear what I was trying to do. I’m not trying to create a typical spinning cube where you press a button and that adds to the rate at which the cube spins. I want to have it just move once for press of the button. In other words, when you press up, it will rotate, say, 5 degress around the x-axis and then stop until the next button is pressed. However, I would also like to have it so when you hold down a button, the up button, for instance, it will continually spin until you release that button. I have this aspect working. Thing I’m having trouble with is, when you press and hold a button, it will rotate, say, 5 degress once, pause, then start spinning constantly until you let go.
The other problem I’m having is when two buttons are pressed at once. If you press and hold up (and it starts spinning up) then press and hold left, it will stop spinning up (completely) and start sping left. I would like it to recognize both keys at once, thus spinning up and to the left.
Obviously, while right now not a huge deal, both of these dilemas would become significant problems in the designing of a game.

Could you not use the rotation rate approach … and merely stop rotating when the particular button is released? … more of a state-driven approach. Just a thought :slight_smile:

Hey, good call! I embarrassed I didn’t think of that myself…
One question, though. I’m probably just being dump, but how do you detect when a button is released? As, obviously, the keyboard function isn’t called when no buttons are being pressed, so you can’t simply say, if this isnt being pressed, do this. Is there a callback for releasing a key? I looked through the list of glut functions on the opengl site, but couldn’t find one.

haha, just kidding. glutKeyboardUpFunc() Right… thanks brcain!