Check if any key is pressed

As the title suggests, how can I check if any key was pressed on this new system? Also how can I know what key it was?

Thank you

1 Like

You can use:


It detects if any key was pressed, but I think it doesn't expose the specific key name? I'm just learning this new Input System myself.


That might work. Do you think there is a way of getting input from any device? Per example:


Do you think this might be possible?

ATM there's no good, simple way to to that. It's on the list for after 1.0 as it's indeed a hole in the system.

Binding-wise, it is possible to do

var action = new InputAction(type: InputActionType.PassThrough, binding: "*/<Button>");

// In update code:
if (action.triggered) //...

but doing so is very inefficient.

An alternative is doing it at the event level but it requires a good chunk of code.

// Sets m_ButtonPressed as soon as a button is pressed on
// any device.
InputSystem.onEvent +=
    (eventPtr, device) =>
        if (!eventPtr.IsA<StateEvent>() && !eventPtr.IsA<DeltaStateEvent>())
        var controls = device.allControls;
        var buttonPressPoint = InputSytem.settings.defaultButtonPressPoint;
        for (var i = 0; i < controls.Count; ++i)
            var control = controls[i] as ButtonControl;
            if (control == null || control.synthetic || control.noisy)
            if (control.ReadValueFromEvent(eventPtr, out var value) && value >= buttonPressPoint)
                m_ButtonPressed = true;
1 Like

I don't dislike that second alternative. It's ugly but it looks like it will work.
The thing is I don't understand what most of those things do, stuff like "IsA(), controls.synthetic, controls.noisy...". Are those documented on the new input's API?

For the most part, yes. We have holes (mostly with lower-level stuff) but both InputControl.synthetic and InputControl.noisy, for example, are documented.

Thanks for the links!

I'm having an issue with Keyboard.current.anyKey.wasPressedThisFrame. If I hold down one key, then press a second key, it remains false. This is a regression from the old system's Input.anyKey.

Is this intended behavior? If so, is there a workaround? Currently I'm iterating through every Key to individually check if it's down this frame, I feel like there must be a better way...

CC @Rene-Damm -- hope it's okay to ping you

1 Like

I'm experiencing the same issue, "anyKey.wasPressedThisFrame" doesn't trigger when holding a second key so shift/ctrl shortcuts I've set up don't function. We're you able to find a solution/workaround?

@NongBenz I wasn't able to find a non-shitty way of doing it, the workaround I'm using is what I already described: I iterate through every Key and check individually whether one is down.

Is there a simpler way to do this now?

1 Like

any updates? @ unity


Is this still tedious, or has an easier way been implemented? I have to admit, I can't believe the new input system shipped without an easy way to accomplish this.


Any luck with this?


"Any key" is supposed to be easy, but it seems it's confusing for both the programmers and the customers
Any update on this though?


Has anyone had any luck finding anything out, as far as a simpler solution?

1 Like

I used #4 and it worked for me

apparently, there's one for the keyboard. haven't tested it yet though.7378889--900194--upload_2021-8-1_17-19-45.png


would anyone like to try the above one out?

1 Like

Dont know how I missed the documentation but this did work.

I ended up using the following and worked great.

1 Like

Well, here's the code then (extracted from here ):

public KeyCode getCurrentKeyDown()
        KeyCode finalKeyCode=KeyCode.None;
        foreach (KeyCode kcode in Enum.GetValues(typeof(KeyCode))){if (Input.GetKey(kcode)){ finalKeyCode = kcode; }}
        if (finalKeyCode == KeyCode.None)
            //Couldn't find key
        return finalKeyCode;


1 Like