Detect all keys but one

I am trying to elaborate a QTE system, so far all good as far as pressing the correct input on time or if the input time runs out, however I can’t seem to find a way to detect if a key other than the one supposed to be pressed has been pressed.

For example if the correct key to press is “space” but the player has pressed “v” then it should be considered also as a fail condition.

Is there something like Input.anyKeyDown except for the correct key you want to keep out?

My best advice is using two functions, like so

function Update()
{
	if(Input.anyKeyDown)
	{
		//Now check if your key is being pressed
		if (Input.GetButton ("Fire1")
		{
			//DO STUFF
		}

		else
		{
			//FAIL
		}
	}
}
1 Like

Great! Thanks

Well now I’m having another problem that is somewhat similar.

I’d like the script to recognize that if I press any key but one it does something, but if I hold that one “excluded” key it recognizes that I’m holding it and if I press any key while holding the previous one it would do something different than just pressing any key of the first condition.

Here is what I tried but as soon as I press in this case space it goes one frame into “You’re holding space” to immediately “You’re holding space + another key” without me having to press another key while holding space.

function Update () {

if (Input.anyKeyDown){
	if (Input.GetKeyDown("space") ){
	print("You're holding space");
		if (Input.GetKeyDown("space")  Input.anyKeyDown){
		print ("You're holding space + another key");
		}
	}
	else{
	print ("It doesn't work");
	}
}
}

thanks man i was searching for this code for a while now :slight_smile: