Solved

about  GLUT, 'glutKeyboardFunc'

Posted on 2004-09-26
2
6,688 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to properly read C++ console input into several variables with scanf 2 40
C++ Code Issue 4 48
One named event, multiple event handlers 2 58
Need some help with design 17 46
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

734 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