Hold a key down long enough for something to happen

how do i make it so that when i hold down a certain key on my keyboard for a certain amount of time, it makes something happen? like if i hold down “K” for 3 seconds, it goes to the next frame.

try putting this in the default script:

this.numberOfSeconds = 3;
this.keyCounter = project.framerate * this.numberOfSeconds;

this will declare and initialize the variable. then in the keydown script put this:

if (key === "your key") {
  this.keyCounter--;
}

this will decrease the counter when the key is held. then in the keyreleased script put this:

if (key === "your key") {
  this.keyCounter = project.framerate * this.numberOfSeconds;
}

this will reset the counter when the key is released. then in the update script put this:

if (this.keyCounter === 0) {
  // do some stuff here
}

this will do something once the counter hits 0.

2 Likes

ayyyyyyy it works! thanks my dude! :)

1 Like