Link to home
Start Free TrialLog in
Avatar of tom_mk
tom_mk

asked on

about GLUT, 'glutKeyboardFunc'

hello,

i having problem with my spacebar

i need to have the space key toggle the animation on and off.
however, i really can't find any relevant example about this topic.

this is wat i've found
==========================================================
   glutKeyboardFunc( processKeys );
   glutSpecialFunc( processSpecialKeys );


void processKeys(unsigned char key, int x, int y) {

      if (key == 27) // escape key
            exit(0);
}

void processSpecialKeys(int key, int x, int y)
{
      switch(key) {
            case GLUT_KEY_UP :
                  pos_y+=2;
                  break;
            case GLUT_KEY_DOWN:
                  pos_y-=2;
                  break;
            case GLUT_KEY_LEFT:
                  pos_x-=2;
                  break;
            case GLUT_KEY_RIGHT:
                  pos_x+=2;
                  break;
      }
}

==========================================================

can anyeone gimme any suggestion?
ASKER CERTIFIED SOLUTION
Avatar of bcsonka
bcsonka

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Hamed Zaghaghi
the ASCII code of spacebar is 32.
so u can check o see if the `key' parameter is 32 in an `if' statement.
u can use Sleep function to puase the program

good luck