GLUT two keys at once


I’m new to this, so I wrote a little program to display a multicolored pyramid that rotates with the arrow keys. No problems at all, but how do I get two keys to function at the same time? I want to be able to hold the up and left keys together, to get the pyramid to rotate around the Z and Y axes simultaneously. Is this possible using the standard glutSpecialFunc? Thanks.

What you can do is declare an erray of boolean values at the top of your source.

bool keys[256];

then inside of the glut keyboard function, each time a key is pressed, let’s say ‘a’, then simply do:
keys[‘a’] = true;
and if the key is unpressed, do:
keys[‘a’] = false;

Hence ‘a’ would be replaced with the ‘unsigned char key’ variable in the function parameters

then inside of your main loop, if you want to test for multiple keys just do:

if(keys[‘a’]) //do something
if(keys[‘b’] && keys[‘c’]) //do something

This will work perfectly and will let you press multiple keys. Hope this helps.

Great, that’s just what I was looking for - I wasn’t even aware there was a glutSpecialUpFunc! Time to RTFM probably…

Thank you for the help.