- Home /
How to Count an Input, key press on keyboard
I am trying to count how many times the user has pressed a certain key on the keyboard.
Something like the code below, except of course the code below increments count by number of frames key 1 was held down.
How can just get the count of that key 1 press? I could add a boolean to keep track of the key pressed/released, but I can't find in the docs how i can get those keyboard events.
var count = 0;
function Update() { if(Input.GetKey("1")) { count++; } }
Answer by StephanK · Aug 10, 2010 at 05:04 AM
Input.GetKeyDown("1")
This returns true on the first frame the key is pressed only.
Input.GetKeyUp("1")
Returns true on release.
Thanks Spree! Of course all in the Scripting references. I was reading the User $$anonymous$$anual ins$$anonymous$$d where I couldn't find those methods.
Your answer
Follow this Question
Related Questions
Activate an input to pickup or search objectes 1 Answer
New Input system holding down a button 2 Answers
Jumping randomly doesn't work 2 Answers
Input.GetMouseButtonDown(0) running through my if statments too quickly 1 Answer
How to have user input behave the same through variable framerates? 1 Answer