Setting a timeout on a keyPressed
in
Programming Questions
•
1 year ago
I'm coding a game where I'd like there to be a limit on how long you can hold a key down. If you press it for any more than say 1 second, you lose a point and it goes back to the "off" state until you release the key and press it again. Any suggestions on how to do this? I'd really rather not use keyReleased(); because it would screw up the timing of the user input (it's a rhythm-based game).
I found this code by rbrauer that cleverly gets around the repeat rate issue, but I can't get my head around how I'd work a timer into it
I found this code by rbrauer that cleverly gets around the repeat rate issue, but I can't get my head around how I'd work a timer into it
- boolean state, pstate;
- void setup() {}
- void draw() {
- state = false;
- state = keyPressed;
- if(state != pstate) println(state); //only react if there's been a change
- pstate = state; //flip it so the starting state is the current state
- }
Thanks!
1