Forum rules - please read before posting.

Best way to detect if any key is pressed?

Hello,

I've got a scene where I want to trigger an action list if any keyboard button is pressed. At the moment, I'm using an active input to detect a specific key, but what sort of setup would be required for it to detect any key?

Thanks!

Comments

  • Best to rely on Unity's own Input.anyKeyDown.

    This could be used to trigger an ActionList directly. If you instead use it to simulate the Active Input's button, though, you can make use of its condition settings so that it can be ignored during e.g. cutscenes:

    using UnityEngine;
    using AC;
    
    public class AnyKeyActiveInput : MonoBehaviour
    {
    
        public int activeInputIndex;
    
        void Update ()
        {
            if (Input.anyKeyDown)
            {
                string inputName = KickStarter.settingsManager.activeInputs[activeInputIndex].inputName;
                KickStarter.playerInput.SimulateInputButton (inputName);
            }
        }
    
    }
    
  • Thanks Chris. I ended up plugging it in to a Rewired event and doing a .Interact() on the action list. Works a charm.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.