question about glutKeyboardFunc
i set up this code:
in main
then in checkNormKeys()
the code works, but it only does one key at a time, how would i enable it to do two keys at once? like if 'd' makes a character move left and 'w' makes it move up, then they are both pressed at the sometime i want it to move up and left at the same time. any ideas?
-brett
in main
Code:
glutKeyboardFunc(checkNormKeys);then in checkNormKeys()
Code:
if (key =='d')
scrollLeft();
else if(key == 'a')
scrollRight();
else if(key == 's')
scrollUp();
else if(key == 'w')
scrollDown();the code works, but it only does one key at a time, how would i enable it to do two keys at once? like if 'd' makes a character move left and 'w' makes it move up, then they are both pressed at the sometime i want it to move up and left at the same time. any ideas?
-brett
By removing every 'else' from that function.
It's all about flow control, man! *hippie-sounding*
It's all about flow control, man! *hippie-sounding*
Code:
static bool keys[255];
...
void keyPressed(unsigned char k, int x, int y)
{
keys[k] = true;
if (keys['h'] && keys['i'])
{
printf("Both h & i are pressed!\n");
}
}
void keyReleased(unsigned char k, int x, int y)
{
keys[k] = false;
}
...
unsigned int i;
for (i = 0; i < 255; ++i)
{
keys[i] = 0;
}
glutKeyboardFunc(keyPressed);
glutKeyboardUpFunc(keyReleased);(This is one of the flakiest points of GLUT, and will break down completely if the user holds a modifier key during either the up-stroke or the down-stroke of the key but not the other. You can get around this somewhat by "de-shifting" the keys yourself, but option and control will continue to be problematic.)

