Simultaneous key presses


I’m currently coding a 3D engine in C and using GLUT to maintain maximum portability.

How do you allow for simultaneous key presses? For example, when I’m moving forward and then I want to strafe, I need to press the ‘forward’ button, let go, then press ‘strafe’ button. is there a way to handle button presses better without having to let go?

also, is there a platform-independent way to detect if you have RELEASED a key button? this would be very helpful to trigger deceleration in a 3D engine so your player doesn’t just stop instantaneously.


Q2: use glutKeyboardUpFunc()

Q1: I’ve never had any problems with simultaneous keypresses in GLUT. Just associate a flag with each control key, set it to true in glutKeyboardFunc and to false in glutKeyboardUpFunc(). Then base your movement on the combination of the various key flags.

thanks a lot for your help. much appreciated.

btw, how did you know about glutKeyboardUp()?

i did not find that in the GLUT API.


Heh… get into the habit of reading the headers. The GLUT API docs aren’t particularly up-to-date.