Problems with GetKeyUp generating text outside Unity

I’m trying to record button presses in a document outside of Unity. The presses are being recorded, but I only want it to print once for every time the button is pressed. I thought using Input.GetKeyUp in Update() would accomplish that, but I’m still getting several outputs for one single button press. This is the code I have now. Can you see anything wrong with it or do you have any suggestions for how I can do this? Thanks!

private string directionChosen;
	
	void Update () {
		string path = @"/Users/saradiaz/museum/Log/responses";
		//string path = @"C:\Users\ccn\Desktop\Sara	rain\Log\coords";
		if (Input.GetKeyUp("right")) {
			directionChosen = "

right";
}
if (Input.GetKeyUp(“left”)) {
directionChosen = "
left";
}
if (Input.GetKeyUp(“up”)) {
directionChosen = "
straight";
}
System.IO.File.AppendAllText(path, System.String.Format(“{0}”, directionChosen));

	}
}

P.s I’ve also tried KeyCode.UpArrow etc instead of the strings.

Well, you’re writing to the file in the Update function. It’s writing directionChosen to coords every frame. While there are many other things wrong with this script, I think that answers why you’re getting multiples.

Oh fine, try this:

public string path; //You could set this is the inspector if you want

void Start(){
    path = "C:\Users\ccn\Desktop\Sara	rain\Log\coords.txt";
}

void Update () {
    if(Input.GetKeyUp(KeyCode.RightArrow)) {
        WriteDirection("right");
    }
    if(Input.GetKeyUp(KeyCode.LeftArrow)) {
        WriteDirection("left");
    }
    if(Input.GetKeyUp(KeyCode.UpArrow)) {
        WriteDirection("straight");
    }
}

private void WriteDirection(string direction){
    System.IO.File.AppendAllText(path,"

"+direction);
}