# keyCode

> The raw key code for keyboard events.

## Definition

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

```csharp
public KeyCode keyCode { get; set; }
```

### Remarks

Used in [EventType.KeyDown](/engine/6000.5/script-reference/unityengine/eventtype/keydown.md) and [EventType.KeyUp](/engine/6000.5/script-reference/unityengine/eventtype/keyup.md) events; this returns [KeyCode](/engine/6000.5/script-reference/unityengine/keycode.md) value that matches the physical keyboard key. Use this for handling cursor keys, function keys etc.

Additional Resources: [Event.character](/engine/6000.5/script-reference/unityengine/event/character.md).

### Examples

```csharp
// Detects keys pressed and prints their keycode

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    void OnGUI()
    {
        Event e = Event.current;
        if (e.isKey)
        {
            Debug.Log("Detected key code: " + e.keyCode);
        }
    }
}
```
