0
0
Unityframework~5 mins

Keyboard input (GetKey, GetKeyDown) in Unity - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does Input.GetKey do in Unity?

Input.GetKey checks if a specific key is being held down during the current frame. It returns true as long as the key is pressed.

Click to reveal answer
beginner
How is Input.GetKeyDown different from Input.GetKey?

Input.GetKeyDown returns true only on the exact frame when the key is first pressed down, unlike Input.GetKey which returns true while the key is held.

Click to reveal answer
beginner
Write a simple Unity C# code snippet that prints "Jump!" once when the spacebar is pressed.
void Update() {
    if (Input.GetKeyDown(KeyCode.Space)) {
        Debug.Log("Jump!");
    }
}
Click to reveal answer
intermediate
Why might you use Input.GetKeyDown instead of Input.GetKey for a jump action?

Because jumping usually happens once per key press, Input.GetKeyDown ensures the jump triggers only once when the key is pressed, avoiding repeated jumps while holding the key.

Click to reveal answer
beginner
What will Input.GetKey(KeyCode.LeftArrow) return if the left arrow key is not pressed?

It will return false because the key is not being held down.

Click to reveal answer
Which Unity input method returns true only on the frame a key is first pressed?
AInput.GetKeyDown
BInput.GetKey
CInput.GetKeyUp
DInput.GetButton
What does Input.GetKey(KeyCode.A) return if the 'A' key is held down?
AFalse
BOnly true on first frame
CTrue
DOnly true on key release
If you want to detect when a key is released, which method should you use?
AInput.GetButtonDown
BInput.GetKey
CInput.GetKeyDown
DInput.GetKeyUp
Which method would you use to check if the spacebar is currently pressed every frame?
AInput.GetKeyDown(KeyCode.Space)
BInput.GetKey(KeyCode.Space)
CInput.GetKeyUp(KeyCode.Space)
DInput.GetButtonDown("Jump")
What will happen if you use Input.GetKeyDown inside Update() to move a character continuously while holding a key?
ACharacter moves only once per key press
BCharacter does not move
CCharacter moves continuously
DCharacter moves on key release
Explain the difference between Input.GetKey and Input.GetKeyDown in Unity.
Think about holding a key versus pressing it once.
You got /3 concepts.
    Describe a scenario in a game where using Input.GetKeyDown is better than Input.GetKey.
    Consider actions that should not repeat if key is held.
    You got /3 concepts.