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.

Originally posted by Hec:
[b]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.[/b]

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

Regards,
Jim

// 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
", key );
keystate[key] = false;
}

void glutKeyboardCallback( unsigned char key, int x, int y )
{
printf( "keydn=%i
", 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.
", i );
}

glutPostRedisplay();
}

int main(int argc, char* argv)
{

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow( "test" );
glutKeyboardFunc( glutKeyboardCallback );
glutKeyboardUpFunc( glutKeyboardUpCallback );
glutDisplayFunc( glutDisplayCallback );
glutMainLoop();

return 0;
}

Thanks Jim!