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 4 of 4

Thread: Delay in initial Key input

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2001
    Posts
    4

    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

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

    Re: Delay in initial Key input

    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
    --
    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: Delay in initial Key input

    Hi!

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

  4. #4
    Advanced Member Frequent Contributor marcus256's Avatar
    Join Date
    Aug 2001
    Location
    Sweden
    Posts
    853

    Re: Delay in initial Key input

    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).

Posting Permissions

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