# GetKey

> Returns true while the user holds down the key identified by the key KeyCode enum parameter.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.5/script-reference/unityengine.md)
* **Assembly:** UnityEngine.InputLegacyModule

## GetKey(KeyCode)

Returns true while the user holds down the key identified by the `key` [KeyCode](/engine/6000.5/script-reference/unityengine/keycode.md) enum parameter.

```csharp
public static bool GetKey(KeyCode key)
```

### Parameters

**** (\[KeyCode]\(/engine/6000.5/script-reference/unityengine/keycode)):&#x20;

### Returns

| Type                                                          | Description |
| ------------------------------------------------------------- | ----------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) |             |

### Examples

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

public class ExampleClass : MonoBehaviour
{
    void Update()
    {
        if (Input.GetKey(KeyCode.UpArrow))
        {
            print("up arrow key is held down");
        }

        if (Input.GetKey(KeyCode.DownArrow))
        {
            print("down arrow key is held down");
        }
    }
}
```

## GetKey(string)

Returns true while the user holds down the key identified by `name`.

```csharp
public static bool GetKey(string name)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)):&#x20;

### Returns

| Type                                                          | Description |
| ------------------------------------------------------------- | ----------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) |             |

### Remarks

**Note**: This API is part of the legacy Input Manager. The recommended best practice is that you don't use this API in new projects. For new projects, use the Input System package. To learn more about input, refer to [Input](/engine/6000.5/script-reference/unityengine/input.md).

[Input.GetKey](/engine/6000.5/script-reference/unityengine/input/getkey.md) will report the status of the named key.  This might be used to confirm a key is used for auto fire.  For the list of key identifiers see [Input Manager](/engine/6000.5/manual/input/legacy/class-input-manager.md). When dealing with input it is recommended to use Input.GetAxis and Input.GetButton instead since it allows end-users to configure the keys.

**iOS, tvOS**: Due platform limitations,  [Input.GetKeyUp](/engine/6000.5/script-reference/unityengine/input/getkeyup.md) event for keyboard events is delayed by about half a second, see UnityView+Keyboard.mm in the generated Xcode project for more information.

### Examples

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

public class ExampleClass : MonoBehaviour
{
    void Update()
    {
        if (Input.GetKey("up"))
        {
            print("up arrow key is held down");
        }

        if (Input.GetKey("down"))
        {
            print("down arrow key is held down");
        }
    }
}
```
