Detect no keys pressed for x amount of time

This might seem like a relatively simple question, but I’m a complete idiot and I’m at my wits’ end trying to do extremely basic code. I’m trying to make a character swap to an idle animation after x amount of time of being idle, but I can’t even achieve a simple test print function with

void Update () {
	if (Input.anyKeyDown == false) {
		print("hello");
	}

without it printing repeatedly due to it updating every frame. How do I make it detect my input (or lack thereof) over a period of time and only do something once?

public float inactivityThreshold = 5f ;
private float lastActivityTime ;
private bool inactive;

 void Update ()
 {
    if (Input.anyKeyDown)
    {
         inactive = false ;
         lastActivityTime = Time.time ;
    }
    if ( !inactive && Time.time - lastActivityTime > inactivityThreshold )
    {
         inactive = true ;
         Debug.Log("Inactive") ;
    }
 }