How to change anyKey in to anyKeyDown? with proper inputString.

this is the problem I’m heaving:

IF I press

a

I get Debug:

false:  Length: 0

For code:

void Update(){
	if (Input.anyKeyDown){
		Debug.Log("false: " + Input.inputString + " Length: " + Input.inputString.Length);
		if (Input.inputString.Length == 1){
			Debug.Log("true: " + Input.inputString);
		}
	}
}

IF I press

a

I get Debug:

false: a Length: 1
true: a

For Code:

void Update(){
	if (Input.anyKey){
		Debug.Log("false: " + Input.inputString + " Length: " + Input.inputString.Length);
		if (Input.inputString.Length == 1){
			Debug.Log("true: " + Input.inputString);
		}
	}
}

This works perfectly EXCEPT I want to fetch only key downs, … How should I do that?

In the last code I also GET

  • 1X false: a Length: 1
  • 1X true: a
  • 2X false: Length: 0

Finally after trying and trying, … I finally figured out how should I do it, …

thanks to @whydoidoit and @Scribe

I learned the complete machanics behind it, … so what I did is:

bool OnDown = false;
void Update(){
    if (OnDown){
        // my code
        OnDown = false;
    }
    if (Input.anyKeyDown){
        onDown = true;
    }
}

so it actually has to pass 1 FRAME in order to get the character in, …

and no @whydoidoit I couldn’t do only with

Input.inpusString > 0

because there was lots of inputs that take 1 length like backslash, enter/return, … Witch are mostly collected before, … and lots of them that take 0 like delete and even more of them, …