How to detect input being hold in new Input System

I have an InputAction in my script, and I use .triggered to detect when the key/gamepad button was pressed that frame, just like through code you can do Gamepad.current.aButton.wasPressedThisFrame.

How can I also check if it’s pressed? Like Gamepad.current.aButton.isPressed.

Also, is there an equivalent of Key for gamepad buttons?

//theory code
var gamepadInput = aButton;
if (Gamepad.current[gamepadInput].isPressed)
//do something

void HoldMe(InputAction.CallbackContext context)
{
if(context.performed) // the key has been pressed
{
//dothething
}
if(context.canceled) //the key has been released
{
//stopdoingthething
}
}

more about the states are here, I use the inspector to assign callbacks, theres probably a more clever way to do it, but this works ok for me. hth
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Actions.html

I’d also be interested in an answer to this.

First, note that when you create controls and have a C# class auto-generated, you need to have your class inherit that. Your controls class is called PlayerInputActions. I don’t see the “Action Map” name, so I will use mine. In the GUI, mine is called “AvatarDefault”. The action is called “Jump”. If you inspect the auto-generated C# class, you will find the namespace, interface, and methods. My action map becomes an interface when generated, and is named IAvatarDefaultActions. Since you don’t list your ActionMap name, I will use mine. Replace it with yours in your code.

liteblue

I know its an old question, but this works for me.

void onHold(InputAction.CallbackContext context) {
            pressedDown = context.ReadValueAsButton();
}