How to specify a time frame for key press?

edited May 2017 in How To...

Hey, I am somewhat new to processing and I am trying to make a sort of game for a school project. It is an interactive game where the player is shown a video and within the last ten-ish seconds they have to make a choice by pressing a key, this will then take them to the next part of the story. My question is, is there a way to specify a time frame within which the player can press the key so that if they press the key outside of that time frame nothing happens? Right now if the key is pressed before the ten second countdown at the end it goes on to the next video, which kind of ruins the experience.

I'm not really sure how to correctly add code to this post so if you need to see any, let me know and I will try to figure it out.

Answers

  • edited May 2017

    You have the right function tagged: millis(). When the moment at which key presses become valid occurs, record the current value of millis(), and also record that value plus 10000. Now in your keyPressed() function, check that the current time (which millis() returns now when the key is pressed) is between those two remembered times. If it is, it's valid so move on. If not, do nothing.

Sign In or Register to comment.