Jump to content
  • Advertisement
Sign in to follow this  
BFK_GoNER

Smooth User Input (Keyboard)

This topic is 4235 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Good day to all, I am making an FPS game using Visual C++ and DirectX 9.0c and I am not at all satisfied with my user-input handling. Until now, the game scheme looks like this: [Main Loop] | - Check user input (using Direct Input) - Calculate the delta time since last frame - ... (reserved for physics and other stuff) - Render | [back to the beginning] Using this setting the game can only detect 1 user-input change per frame. What I would love to have is to get a sort of a separate thread which could detect the keyboard input separately from the main loop and generate a keyboard change stack. I have been trying to play around with all sorts of threads but the best result was seen when I was using WM_KEYDOWN/WM_KEYUP in WindProc. The problem with that however, is that the keyboard detection goes like this: [Tick]-...(half a second pause]...- [Tick][Tick][Tick][Tick][Tick].. Can anybody tell me what the cause of this half-a-second pause is and how to avoid it? I have done some investigation and I figured out that my program does not recieve any keyboard messages during this annoying half-a-second break! What do I do?..

Share this post


Link to post
Share on other sites
Advertisement
In your input loop, check until no more inputs are waiting


while (inputs)
{
ProcessInputs();
}

Share this post


Link to post
Share on other sites
You could use these but since there is such a long time between frames I have another idea. Why not run the check-input function several times in each frame. That would probably be better, I think.

I would not recommend using a different thread though, other then WindProc, since you in that case must set the priority way down to not make the performance of the program worse, for single core processors.

Share this post


Link to post
Share on other sites
Quote:
Original post by BFK_GoNER
I have been trying to play around with all sorts of threads but the best result was seen when I was using WM_KEYDOWN/WM_KEYUP in WindProc. The problem with that however, is that the keyboard detection goes like this:

[Tick]-...(half a second pause]...- [Tick][Tick][Tick][Tick][Tick]..

Can anybody tell me what the cause of this half-a-second pause is and how to avoid it?

I have done some investigation and I figured out that my program does not recieve any keyboard messages during this annoying half-a-second break! What do I do?..

That is simply caused by the auto-repeat feature that is quite handy in most applications. Go to any textbox, open notepad, or something, and hold down a key. You'll see the exact same effect. This can be changed in the control panel to an extent, but you obviously can't expect other people to change their keyboard settings just to play a game. The options are to use unbuffered input (just read current states, using functions like GetKeyboardState(), or GetAsyncKeyState(), and figure out when it went up or down manually, though that can miss really quick down/up transitions), or use some form of raw input (the Win32 Raw Input API, DirectInput, SDL, et cetera).

When you say Check user input (using Direct Input), what exactly did you mean by that anyway? There isn't anything fundamental that limits how to check for multiple input events per frame with DirectInput, as others have already mentioned.

Share this post


Link to post
Share on other sites
As Agony said, it's just standard keyboard repeats - you can use WM_KEYDOWN/WM_KEYUP, but you should check the message information to see if the key was already down and if so ignore the repeat message and instead maintain the state yourself. The only real reason to do it this way would be to be absolutely sure you catch all keypresses and know exactly when the key was pressed - if you slow down to a few frames a second, you won't miss keystrokes this way.

On the other hand, using DirectInput or GetKeyboardState etc lets you not worry about that because it maintains the buffer for you.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!