• Advertisement
Sign in to follow this  

Keyboard Issue

This topic is 4404 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

Well I am using DirectInput in C++ to get what keys have pressed in my game. From the DirectInput, when a key is pressed it is sent a textinput box class that prints whats been pressed. My issue with it comes from when a key is being pressed it continues sending buffer data to the textinput box and fills the box up after just one press. I am trying to keep a second delay betwen 1 press then fill the box, using sleep() doesnt help, just lags up the game. Anyone have any solutions?

Share this post


Link to post
Share on other sites
Advertisement
You can use buffered input instead of immediate input. However, you can also do this using immediate input. Do something like this:
initially, set last_time_key_pressed = 0
whenever a key is pressed
if current_time - last_time_key_pressed < delay
ignore key press
else
process key press
last_time_key_pressed = current_time

In the above pseude-code, delay = 1/typematic_rate (number of characters/s).

Share this post


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

  • Advertisement