Search Unity

Input System - checking if specific key is down or pressed, using Key enum value

Discussion in 'Input System' started by mgeorgedeveloper, Apr 7, 2021.

Thread Status:
Not open for further replies.
  1. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    326
    Hey all,

    I see there is a Key enum in the new system:

    https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/api/UnityEngine.InputSystem.Key.html

    I understand how to get a keyboard object via "Keyboard.current".

    However, I can't seem to find a simple way to check if a particular key is pressed by using a value from the Key enum.

    I know there is a set of hardcoded properties, one per key. But I have a case where I would like to check the key down state (or pressed this frame) using a Key enum value.

    Any ideas?

    Thanks!
     
  2. You mean this?
     
    ZoopTEK and esco1979 like this.
  3. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    326
    LOL yes I do. I must have missed it in the sea of per-key properties! You won't believe how much time I've spent looking for this.
     
  4. esco1979

    esco1979

    Joined:
    Mar 18, 2014
    Posts:
    138
    I was just looking for that too. Didn't even know if it existed or not. Thanks for pointing it out!

    EDIT: for anyone who might need it, here is the gamepad one. Though I am admittedly having trouble figuring out how to even use it to return the value of each button as a test (which was easy to do with the keyboard one). Sadly there seems to be no enum for the 4 cardinal directions on the analog sticks: https://docs.unity3d.com/Packages/c...ngine.InputSystem.LowLevel.GamepadButton.html
     
    Last edited: Apr 25, 2021
  5. The magic of reading the documentation. You acquire knowledge about stuff.
     
Thread Status:
Not open for further replies.