Keyboard input in userwidget

Hey,

I know this is an old post, but in case anyone else needs help getting a widget to register key presses I’ve found two ways:

1 - Using “Listen for Input Action”, whenever you press a key associated with that action mapping it will trigger the “callback” event.

You have to “Set Input Mode Game And UI” for this to work.

“Consume” makes sure that this widget takes priority on what listens to that key press, e.g. so that when you press “jump” it isn’t calling jump events on your character and in your widget, just the widget.

With this method you can change the keys associated with an action mapping and that change will be reflected in all widgets that you use this method with.

If an action mapping isn’t specifically being “listened” to in the widget, your pawn will still receive that input.

This method doesn’t seem to work if the game is paused, because the pawn will then receive no input.

2 - Overriding the “OnKeyDown” function to trigger a custom event that will do different actions based on what key was pressed.

I set the input mode to UI only.

Make sure to go to the widget options under “interaction” and set “is Focusable” to true.

With this method you can do it while the game is paused and the pawn won’t be receiving inputs.

If you want to add another key to trigger an event you will have to manually add this change to all your widgets that you use this method with (I haven’t figured out a way of avoiding that).

13 Likes