# GetKeyDown

> Returns true during the frame the user starts pressing down the key identified by the key KeyCode enum parameter.

## Definition

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

## GetKeyDown(KeyCode)

Returns true during the frame the user starts pressing down the key identified by the `key`[KeyCode](/engine/6000.7/script-reference/unityengine/keycode.md) enum parameter.

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

### Parameters

**** (\[KeyCode]\(/engine/6000.7/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.GetKeyDown(KeyCode.Space))
        {
            Debug.Log("space key was pressed");
        }
    }
}
```

## GetKeyDown(string)

Returns true during the frame the user starts pressing down the key identified by `name`.

```csharp
public static bool GetKeyDown(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.7/script-reference/unityengine/input.md).

Call this function from the `Update` function, since the state gets reset each frame. It will not return true until the user has released the key and pressed it again.

When dealing with input it is recommended to use [Input.GetAxis](/engine/6000.7/script-reference/unityengine/input/getaxis.md) and [Input.GetButton](/engine/6000.7/script-reference/unityengine/input/getbutton.md) instead since it allows end-users to configure the keys.

### Examples

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

public class ExampleClass : MonoBehaviour
{
    void Update()
    {
        if (Input.GetKeyDown("space"))
        {
            Debug.Log("space key was pressed");
        }
    }
}
```
