Can someone help me use GetKeyDown functions with this script. I've tried so many combinations

This script works fine using UI “Buttons”
However, I am looking to use GetKeyDown & GetKeyUp functions to start and stop the timer.
It seems logical to do but I just can’t find a solution using Input.GetKeyDown functions.

float val;
bool timerActive;
public Text timerText;

// Start is called before the first frame update
void Start()
{
    val = 0;
    timerActive = false;
}

void Update()

{
    if (timerActive)

    {
        val += Time.deltaTime;
    }

    double b = System.Math.Round(val, 2);

    timerText.text = b.ToString("F2");
}

public void startbutton()
{
    timerActive = true;
}

public void stopbutton()
{
    timerActive = false;
}

Hi @Var1g !
It would be enough just to add this snippet of code at the beginning of the Update function.

 if (Input.GetKeyDown(KeyCode.Q))
     timerActive = true;

if (Input.GetKeyDown(KeyCode.E))
    timerActive = false;

And you can put your own keys there instead my **Q ** and E

Hope it helps!

Have you tried using th