How do I use a keyboard button to trigger a UMG button to register as "Pressed"?

This may seem like a dumb question but I can’t figure it out for the life of me.

What I’m trying to do is have the UI give visual feedback when a buton is pressed on the keyboard. For instance; The player presses the “F” key and the UI button lights up indicating they are attacking.

Is there a way to triggers the button being pressed by binding it to an input mapping? I feel like every game on earth does this to some extent and I don’t know why I can’t tell the button to be pressed in code.

I trying to keep everything in C++ as I am focusing on learning it. Thanks in advanced!
Neil

Input bindings are set up in the editor Project Settings under the Input category.

You want to do your bindings in SetupPlayerInputComponent in your player character.

If you create an input named “Attack” the binding will be something like this:

PlayerInputComponent->BindAction("Attack", IE_Pressed, this, &AMyAwesomeCharacter::PerformAttack);

This then binds whatever function you define here, PerformAttack() in this case, to fire when you do this key action.

I think there is a misunderstanding. What I want is a umg button to register as pressed like a click when I press a key on the keyboard.

For instance I press “f” and the menu ui button that says “attack” gets lighter. I want to bind the input action to a ui button not just bind the input action to a function

A great example is when you press the “b” button on a game pad while in a menu and the ui element that says “B - back” lights up before executing the action of going back.

Does that make sense?

You can use ListenForInputAction in your UUserWidget Button to register a callback. You will still need to write the function to set the hilight state, regardless. Make sure you read the doc I posted above so you are familiar with how the input priority is handled.

1 Like