Skip to main content
GameDev.net gamedev.net
🔒 Locked

DirectInput - Stopping input on held key

Started by Citizen Erased Aug 30, 2007 at 8:18 AM 4 replies 1.6k views
Original Post
Citizen Erased
Citizen Erased
I'm trying to get input from the keyboard while a user types. I don't want to use cin as I don't want a console window up. However, as DirectX polls they keyboard every frame, if a user has their finger on a key for more than one frame, instead of getting the pressed key once, they get it multiple times e.g. pressing 'G' would result in GGGGGGGGGG. Is there anyway for DirectInput to only take the input once while the key is down until it is let up again? If not, is there another input alternative? Cheers.
Evil Steve
Evil Steve
Quote:
Original post by Citizen Erased
I'm trying to get input from the keyboard while a user types. I don't want to use cin as I don't want a console window up. However, as DirectX polls they keyboard every frame, if a user has their finger on a key for more than one frame, instead of getting the pressed key once, they get it multiple times e.g. pressing 'G' would result in GGGGGGGGGG. Is there anyway for DirectInput to only take the input once while the key is down until it is let up again? If not, is there another input alternative? Cheers.
Nope. DirectInput should not be used for keyboard or mouse input at all. Some reasons:
  • Window messages are faster (DirectInput just creates another thread to read window messages)
  • Window messages give you things like key repeat for free, DirectInput doesn't
  • Window messages handle shifted letters and caps/num/scroll lock properly, DirectInput doesn't
  • Window message obey the users control pannel settings, DirectInput does not
  • Window messages are "free". They get sent to your window without you having to write pages and pages of code to initialise a DirectInput device
  • Microsoft recommend that you do not use DirectInput for keyboard or mouse input:
    Quote:
    Overall, using DirectInput offers no advantages when reading data from mouse or keyboard devices, and the use of DirectInput in these scenarios is discouraged.
  • Mike.Popoloski
    Mike.Popoloski
    These are starting to get amusing:

    Evil Steve Replying to DirectInput Posts:

    1) This Thread.

    2) [DirectInput] Return Pressed Button.

    3) I have some problems with DirectInput.

    4) Input On Windows.

    5) Restore Lost Mouse Device.

    6) [MDX] DirectInput SetCooperativeLevel.

    7) directinput problem.

    8) DirectInput problem.

    9) DirectInput Buffered Keyboard.

    Hmmm... That's only going back about a month.
    Mike Popoloski | Journal | SlimDX
    KOzymandias
    KOzymandias
    I don't know why so many people use DirectInput for mouse/keyboard, but as soon as I get back home, I will no longer be one of them :).

    Thx Evil Steve.
    jollyjeffers
    jollyjeffers
    Quote:
    Original post by Mike.Popoloski
    These are starting to get amusing
    Yup, I was contemplating setting up a sweepstake for guessing the time between a DInput question being posted and the time when Steve posted [lol]

    Jack
    <hr align="left" width="25%" />
    Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |

    Topic Locked

    This topic has been locked by a moderator. New replies are not allowed.

    Sign in to reply to this topic.