Why key events doesn't work in Widgets?

And you must use On Key Down always.

Also, you only have an On Key Down function, if you have to handle different possible keys, what is the proper way to check key?

j89DyHv1

Have you given the widget keyboard focus?

1 Like

I would not recommend hardcoded Keys.
In the Project Preferences, under “Input”, you can define Action and Axis Mappings.
Those Action Mappings can hold multiple keys in one single Action.

Here are my Functions, to check the OnKeyDown Input Key, against an Action Mapping of the Preferences:

1.:
Takes in a >KeyEvent<, an Enum containing [ActionMapping, AxisMapping] a Variable of >Type Name<.
The Function returns a bool
You need one local Variable of Type >Bool<.

The Second Function is
Takes in a >KeyStructure (=Key)<, an Enum containing [ActionMapping, AxisMapping] a Variable of >Type Name<.
The Function returns a bool
You need one local Variable of Type >Bool<.

I put both Functions inside a BlueprintFunctionLibrary… so i can use them everywhere in the Project.

So… f.e.:
You want to check if one of the Keys of the “Interact” Action Mapping is pressed,
You simply do this:

Same way for KeyByStructure, when the initial Node of a Function is giving a KeyStructure, instead of a KeyEvent.

1 Like

I would recommend using the enhanced input plugin for this, since it also allows way easier key remapping and multiple keymapping profiles.

Regardless, Key Events are one of the many functions that dont work in widget blueprints by default.
The way I deal with this is to recognize those types of events in a player controller blueprint and have that communicate with the Widgets that need to receive that information.

how do you let them communicate?

you can create and implement an interface in the widget but you will need to get a reference to your widget to send any data to it.

1 Like

@Goeddy

I took your advice and made a BPI to pass when I pressed the Esc key (IA_Escape) to the Pause Menu WidgetBP. It’s printing a string successfully when pressing Esc in the Pause menu, but there is nothing happening. Furthermore, when I plug it into the same code the Resume button uses, it still doesn’t work.

I’ve checked that my IA_Escape is “trigger when paused”, and I’ve set “Set Input Mode Game And UI”. I’ve even tried to run the Event Press Esc into a duplicate of the Set Game Paused and Remove from Parent nodes with no resolve.

Attached are the Player Controller and PauseMenu Widget Event graphs.


Could you elaborate on your comment?