Solved

about  GLUT, 'glutKeyboardFunc'

Posted on 2004-09-26
2
6,443 Views
Last Modified: 2008-01-09
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?
0
Comment
Question by:tom_mk
2 Comments
 
LVL 2

Accepted Solution

by:
bcsonka earned 500 total points
ID: 12157190
Hi,

In the processKeys function check for (key == 32) to check to see if the spacebar is pressed.  Here's an example . . .

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

void processKeys(unsigned char key, int x, int y)
{
     if(key == 27) // escape key
     {
          exit(0);
     }
     else if(key == 32) // spacebar key
     {
          // toggle animation
     }
}

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

I hope that helps.
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 12198349
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
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Embarcadero C++ Builder XE2 TDateTime 8 75
How to convert MFC::CString to UTF8 wchar_t* 10 279
Problem with SqlConnection 4 178
Beginner to Unreal Engine 4 5 94
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question