unity key detection

C#
if (Input.GetKeyDown(KeyCode.Space))
        {
            print("space key was pressed");
        }    void Update()
    {
        if (Input.GetKeyDown("space"))
        {
            print("space key was pressed");
        }
    }using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    void Update()
    {
        if (Input.GetKeyDown("space"))
        {
            print("space key was pressed");
        }
    }
}KeyDown
Source

Also in C#: