unity button pressed property code example

Example 1: how to get the name of the button pressed in unity

//this is Unity pared with C#

using UnityEngine.EventSystems;

public class Class : Monobehaviour
{
	//Call this function when the button is pressed
    public void ButtonClicked()
    {
    	string name = EventSystem.current.currentSelectedGameObject.name;
    }
}

Example 2: unity key pressed

using UnityEngine;

public class Egsample_script : MonoBehaviour
{
    [SerializeField] KeyCode your_key;
    //select a key under inspektor
    void Update()
    {
        if (Input.GetKey(your_key))
        {
            print("your selekted key was pressed");
        }
    }
}