Delay in initial Key input

Hello ,
I am writing a game and I am using GLUT .
I need to have continuous key input . If I hold a key down for a while , I expect my “keyboard()” function to receive continuous input. GLUT is giving me a slight lag between the first and second recognition of an input key . After that initial delay it is continuous . Is there any way around this initial delay ? Do I need to use DirectInput ?

Thanks

Originally posted by chaney:
Hello ,
I am writing a game and I am using GLUT .
I need to have continuous key input . If I hold a key down for a while , I expect my “keyboard()” function to receive continuous input. GLUT is giving me a slight lag between the first and second recognition of an input key . After that initial delay it is continuous . Is there any way around this initial delay ? Do I need to use DirectInput ?
Thanks

I believe glut sends messages when it
receives them. So the secondary messages your
getting are probably key repeat messages.
When these are fired is based on the user’s
keyboard repeat settings.

The best way to do this is to track the
keyboard state using an array, something
like this:

bool array[256]

keyboard( int key, int state )
{
if ( state == down )
array[key] = true;

if ( state == up )
array[key] = false;
}

and in a timer create your own
messages:

timer( id )
{
if array[key] == true
dosomething;
}

Glut kinda sucks for keyboard input if your
on win32. For a better library you might try Cpw
(Cpw Home) which has
a better interface and has support for
the tracking example above build in.

Regards,
Jim

Hi!

Maybe you want to use GLFW, i’ve read its documentation and it has especial functions ready to use for your problem.

Yes, GLFW is much better suited for using the keyboard as a game input device. The next release will have some further improvements regarding keyboard input (numeric keypad keys are detected, and the X11 and Win32 versions behave more alike).