---
title: "GetButton and GetKey"
content_type: tutorial
url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/getbutton-and-getkey?language=en"
language: en
container_type: course
container_title: "Beginner Scripting"
container_url: "https://learn.unity.com/course/beginner-scripting-old.md?language=en"
unit_title: "Beginner Scripting"
unit_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting?language=en"
standalone_markdown_url: "https://learn.unity.com/tutorial/getbutton-and-getkey.md?language=en"
previous_title: "Destroy"
previous_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/destroy-i?language=en"
previous_markdown_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/destroy-i.md?language=en"
next_title: "GetAxis"
next_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/getaxis-o?language=en"
next_markdown_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/getaxis-o.md?language=en"
difficulty: beginner
duration_minutes: 5
unity_version:
  - "2019.3"
  - "2019.2"
  - "2019.1"
  - "2018.4"
  - "2018.3"
  - "2018.2"
  - "2018.1"
  - "2017.4"
  - "2017.3"
  - "2017.2"
  - "2017.1"
  - "5.x"
  - "4.x"
supported_unity_versions:
  - name: "2019.3"
    url: "https://learn.unity.com/tutorial/getbutton-and-getkey.md?language=en&version=2019.3"
  - name: "2019.2"
    url: "https://learn.unity.com/tutorial/getbutton-and-getkey.md?language=en&version=2019.2"
  - name: "2019.1"
    url: "https://learn.unity.com/tutorial/getbutton-and-getkey.md?language=en&version=2019.1"
  - name: "2018.4"
    url: "https://learn.unity.com/tutorial/getbutton-and-getkey.md?language=en&version=2018.4"
  - name: "2018.3"
    url: "https://learn.unity.com/tutorial/getbutton-and-getkey.md?language=en&version=2018.3"
  - name: "2018.2"
    url: "https://learn.unity.com/tutorial/getbutton-and-getkey.md?language=en&version=2018.2"
  - name: "2018.1"
    url: "https://learn.unity.com/tutorial/getbutton-and-getkey.md?language=en&version=2018.1"
  - name: "2017.4"
    url: "https://learn.unity.com/tutorial/getbutton-and-getkey.md?language=en&version=2017.4"
  - name: "2017.3"
    url: "https://learn.unity.com/tutorial/getbutton-and-getkey.md?language=en&version=2017.3"
  - name: "2017.2"
    url: "https://learn.unity.com/tutorial/getbutton-and-getkey.md?language=en&version=2017.2"
  - name: "2017.1"
    url: "https://learn.unity.com/tutorial/getbutton-and-getkey.md?language=en&version=2017.1"
  - name: "5.x"
    url: "https://learn.unity.com/tutorial/getbutton-and-getkey.md?language=en&version=5.x"
  - name: "4.x"
    url: "https://learn.unity.com/tutorial/getbutton-and-getkey.md?language=en&version=4.x"
last_updated: "2026-08-04T14:24:07.000Z"
---

# GetButton and GetKey

Learn to read button and key input in Unity and adjust input axes using the Unity Input Manager.

This tutorial demonstrates how to get a button or a key for input in a Unity project, and how these axes behave or can be modified with the Unity Input manager.

Part of: [Beginner Scripting project](https://learn.unity.com/project/beginner-gameplay-scripting)

Previous Tutorial: [Destroy](https://learn.unity.com/tutorial/destroy-i?projectId=5c8920b4edbc2a113b6bc26a)

Next Tutorial: [GetAxis](https://learn.unity.com/tutorial/getaxis-o?projectId=5c8920b4edbc2a113b6bc26a)

## 1. GetButton and GetKey

[Video](https://connect-mediagw.unity.com/h1/20220104/videos/19687079-9596-4707-986d-05e6e946e1b0_U_Beginner_15_GetButtonandGetKey.mp4)

## **KeyInput**

```csharp
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class KeyInput : MonoBehaviour
{
    public Image graphic;
    public Sprite standard;
    public Sprite downgfx;
    public Sprite upgfx;
    public Sprite heldgfx;
    public Text boolDisplay1;
    public Text boolDisplay2;
    public Text boolDisplay3;

    void Start()
    {
        graphic.sprite = standard;    
    }

    void Update()
    {
        bool down = Input.GetKeyDown(KeyCode.Space);
        bool held = Input.GetKey(KeyCode.Space);
        bool up = Input.GetKeyUp(KeyCode.Space);

        if(down)
        {
            graphic.sprite = downgfx;
        }
        else if (held)
        {
            graphic.sprite = heldgfx;
        }
        else if (up)
        {
            graphic.sprite = upgfx;
        }
        else
        {
            graphic.sprite = standard;
        }

        boolDisplay1.text = " " + down;
        boolDisplay2.text = " " + held;
        boolDisplay3.text = " " + held;
    }
}
```

## **ButtonInput**

```csharp
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class ButtonInput : MonoBehaviour
{
    public Image graphic;
    public Sprite standard;
    public Sprite downgfx;
    public Sprite upgfx;
    public Sprite heldgfx;
    public Text boolDisplay1;
    public Text boolDisplay2;
    public Text boolDisplay3;

    void Start()
    {
        graphic.sprite = standard;    
    }

    void Update()
    {
        bool down = Input.GetButtonDown("Jump");
        bool held = Input.GetButton("Jump");
        bool up = Input.GetButtonUp("Jump");

        if(down)
        {
            graphic.sprite = downgfx;
        }
        else if (held)
        {
            graphic.sprite = heldgfx;
        }
        else if (up)
        {
            graphic.sprite = upgfx;
        }
        else
        {
            graphic.sprite = standard;
        }

        boolDisplay1.text = " " + down;
        boolDisplay2.text = " " + held;
        boolDisplay3.text = " " + held;
    }
}
```
