PDA

View Full Version : C++ Stop continued key press


Ribbonic Plague
Sep 17, 2009, 11:13 AM
Hello everyone!

Just wondering if any of you know if there's a way to stop continued keypress?

For example, if I have something that increments int Counter by one every time a key is pressed, if I press a key without actually lifting my finger, it shouldn't continue to increment. It should only increment once per press.

Thanks for your help!

Perito
Sep 17, 2009, 11:20 AM
You can trap the key down and key up events. Once a Key Down has occurred, you can allow it to increment once, and prevent anything from incrementing a second time until the Key Up event has occurred. Just use a Boolean and set it in an IF block in the Key Down event. Then clear it in the Key Up event.

Ribbonic Plague
Sep 17, 2009, 11:23 AM
Whoah rep to you for your super fast answer!

Thanks for the suggestion. Let me try this out...