Detecting a key hasn't been pressed

  • I'm making a very simple arm-wrestling minigame as part of something larger and I've got it working fairly well. It's just a case of speed-tapping the space bar to win. The opponents score increases all the time but I'd like for it to increase much faster if the space bar hasn't been touched for a couple of seconds. What the simplest way of doing this (essentially, detecting that a key hasn't been pressed for x amount of time)?

  • Run an event that, every tick, increases a variable (let's call it spaceTimer) by 60*dt.

    When your player presses the spacebar, set spaceTimer to 0.

    Then, depending on what your other events look like, check if spaceTimer > 60 or whatever amount of time you want, and if it is then increase the opponent's score by an increased amount. Or increase the score by a factor of spaceTimer, if you want it to be non-linear.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks so much! I feel a bit silly now for failing to see that - I actually used a similar timer for something else yesterday...

    These forums are great for a beginner like me. I really appreciate such helpful and prompt feedback.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)