Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Keyboard and GLUT

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2000
    Location
    Mexico
    Posts
    22

    Keyboard and GLUT

    Hi!

    I need to know the state of keys (pressed, realeased), i saw the example in the new OpenGL Toolkit FAQ and there is an half-answer for this, becouse in my glut.h (version 3) file, i didn't find any function where i can register a:
    keyboardfunc( int key, int state )
    callback function

    So how do i register this callback, or how do i call this function?

    Thanks.

  2. #2
    Junior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    133

    Re: Keyboard and GLUT

    Originally posted by Hec:
    Hi!

    I need to know the state of keys (pressed, realeased), i saw the example in the new OpenGL Toolkit FAQ and there is an half-answer for this, becouse in my glut.h (version 3) file, i didn't find any function where i can register a:
    keyboardfunc( int key, int state )
    callback function

    So how do i register this callback, or how do i call this function?

    Thanks.
    I'll update the faq with this example code -
    hope this helps.

    Regards,
    Jim

    Code :
    // gluttest.cpp : Defines the entry point for the console application.
    //
     
    #include "stdafx.h"
    #include <windows.h>
    #include "glut.h"
    #include <stdio.h>
    #pragma comment( lib, "glut32" )
     
    static bool keystate[256];
     
    void glutKeyboardUpCallback( unsigned char key, int x, int y )
    {
        printf( "keyup=%i\n", key );
        keystate[key] = false;
    }
     
     
    void glutKeyboardCallback( unsigned char key, int x, int y )
    {
        printf( "keydn=%i\n", key );
        keystate[key] = true;
    }
     
    void glutDisplayCallback( void )
    {
      Sleep(100);
     
      for ( int i=0; i <= 255; i++ ) 
      {
        if ( keystate[i] == true ) 
          printf( "ASCII key %i is pressed.\n", i );
      }
     
      glutPostRedisplay();
    }
     
    int main(int argc, char* argv[])
    {
     
     
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
        glutCreateWindow( "test" );
        glutKeyboardFunc( glutKeyboardCallback );
        glutKeyboardUpFunc( glutKeyboardUpCallback );
        glutDisplayFunc( glutDisplayCallback );
        glutMainLoop();
     
    	return 0;
    }
    --
    Jim Mathies http://www.mathies.com/

    \"The best way to predict the future is to invent it."

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2000
    Location
    Mexico
    Posts
    22

    Re: Keyboard and GLUT

    Thanks Jim!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •