How to setup a Coroutine so that it can press a KeyCode for a certain amount of time?

I have a List of KeyCodes and also a list of Float which stores Time.time - startTime

I wanted so that my character can move based on the stored keys in list and press the buttons for how long it has been pressed when I recorded it. This is my code;

	IEnumerator RelayInputs(){
		for (int i = 0; i < keyList.Count; i++){
			
			lastKey = keyList*;*
  •   		character.Move(lastKey);*
    
  •   		yield return new WaitForSeconds (0.5f);*
    
  •   	}*
    
  •   }*
    

I haven’t added the StreamReader functions to read the keys from the .txt file
I may also need a guide on that.
Regards.

A better solution is to map those KeyCodes to certain actions (methods).

Instead of programmatically holding down a key for a certain amount of time, just call the method to perform the respected actions the amount of times appropriate for the time the key was held down.

This is better OO design and allows you to change the definition of the action independent of the key press that causes it.