Checking if two random keys are pressed at the same time?

Hi!

I’m developing a game in which there are two lights. If you press the correct right key and the correct left key at the same time (on your keyboard), both lights are turned on and bomb is deactivated.

The thing is the keys to be pressed are generated randomly at the beginning of the game. How can I check if they are both pressed at the same time? Maybe I can get the KeyCode of the keys to be pressed somehow?

Thanks!

You can use Input.GetKey()/Input.GetKeyDown and pass a string or KeyCode enum.

String labels for the keys can be seen at the bottom of this page:

And the KeyCode enum here:

Remember that it’ll be nearly impossible for someone to press two keys at the exact same frame, so you should use GetKey() and a bool so it doesn’t trigger repeatedly.

    bool isBombActive = true;
	string defuseKeyRight = "k"; //lowercase for normal letters
	KeyCode defuseKeyLeft = KeyCode.S;

	void Update ()
	{
		if(isBombActive)
		{
			if(Input.GetKey(defuseKeyRight)) //User is pressing the right side key
			{
				if(Input.GetKey(defuseKeyLeft)) //The left side key is also pressed
				{
					isBombActive = false;
					Debug.Log("Bomb deactivated.");
				}
			}
		}
	}