Detect which key was used for input (gamepad or keyboard)

Hello everyone, I am just adding a sprint function to my character. Currently I have it set up so that if the player clicks the left joystick on gamepad, and the current velocity is above a certain amount, it makes the player run. I also would like to add a sprint for the keyboard, so that if the player is holding shift, the player runs, but stops running when they let go of shift.

The problem is that the input for gamepad should keep running once released, but for keyboard, should stop running when released. Is there any way to tell if it was the keyboard or gamepad that triggered the input?

Just don’t attach anything to the gamepad button release event? You could have it click on and click off with just a branch node like this.

Yes, but I will need to be able to bind other controls to that input, so what else is available?

From reading your post, I believe you are asking the following questions:

1) How do I get the gamepad to keep dashing after the button is pressed?
This is pretty simple. Do a check to see if the player’s velocity is >= a specific amount - 600 for example. If this is true when the player presses the dash input on the gamepad, then switch the the player to a different state called sprinting that changes the character movement’s max walk speed to whatever desired new max speed you want. Now, if the player chooses to stop moving then you want to check if the velocity has dropped below a certain point - like 600 again for example - and if true, then you want to switch the player back from the sprinting state to whatever default movement state was being used before. One simple idea for doing the check that comes to mind is using a gate with a tick function that starts off closed, but opens once players have successfully switched to the sprint state.

2) How do I get the keyboard to dashing only while the dash input is pressed?
This is easier to do than the gamepad press functionality. All you would do is update it the same way as with the gamepad in pressing the sprint input key should switch the player to the sprinting state, and then once that key is released it should switch right back to the original movement state. However, I can’t tell if you are also asking how to make it sprint automatically without holding down an input key for movement on keyboard - like some games have done before.

3) How can I swap between using both controls seamlessly during runtime?
This is pretty simple to do. Just use a bool tell which control is being used. For example, when input from the keyboard/mouse is received then mark a bool such as ‘KeyboardMode’ to true, and set ‘GamepadMode’ to false. And vice-versa with gamepad input.

Well, I am already doing #1, and for #2, I have no way to detect whether or not it was a gamepad or keyboard event using just one action mapping.

You can make a second action mapping that does the exact same function as another, and assign that to only be fired off by events from gamepad input while the other one only uses keyboard input.

Alright, I just figured there may be a way to find input event, but I will do that then.

Search “pressed” “held” or “down” something like that. Theres a node that will check if the player is holding a key or had pressed a key in the last frame (two different nodes)

I understand that I am writing very late. But it helped me.