PDA

View Full Version : Delay in initial Key input



chaney
04-25-2002, 10:25 PM
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

jmathies
04-26-2002, 12:05 PM
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
(http://www.mathies.com/cpw/) which has
a better interface and has support for
the tracking example above build in.

Regards,
Jim

Hec
05-03-2002, 08:28 AM
Hi!

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

marcus256
05-12-2002, 09:45 PM
Yes, GLFW (http://hem.passagen.se/opengl/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).