Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   C (https://www.askmehelpdesk.com/forumdisplay.php?f=438)
-   -   C++ Stop continued key press (https://www.askmehelpdesk.com/showthread.php?t=397263)

  • Sep 17, 2009, 11:13 AM
    Ribbonic Plague
    C++ Stop continued key press
    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!
  • Sep 17, 2009, 11:20 AM
    Perito

    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.
  • Sep 17, 2009, 11:23 AM
    Ribbonic Plague

    Whoah rep to you for your super fast answer!

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

  • All times are GMT -7. The time now is 07:45 PM.