OnKeyDown in UMG is not getting called

I have seen a similar thread here in the forum, but my issue is not like that. Actually, overriden function OnKeyDown is getting called for all keys, except for keys such as Space bar, Enter Key, Arrow keys, etc

Anyone knows the reason?

I can confirm that at default settings the above will intercept all keys, including arrow keys, spacebar and even Esc correctly. If you are experiencing different behaviour, look into the focusability of the widget and its input priority. Perhaps something else is handling (and consuming) the input of the keys that do not register for you.

How to solve it? Any ideas?
Currently the focus is on an EditableTextBox. May be the textbox is handling the inputs. But how to solve it.

Thank you for your support.

Why is this in C++ forum?

Actually, I am trying to implement the same in C++. I dont think that we have that much privilege in BP to override EditableTextBox from handling keyboard inputs.

Not exactly overriding, but preventing EditableTextBox from consuming it completely, so that OnKeyDown will receive it.

Not sure if I understand what you’re trying to achieve. You want to type and simultaneously have the same key input fire an additional event?

If that’s the case, you could override the (editable) text box’ *OnTextChanged * event, it returns the text that has been typed, convert to string, fetch the last char and from here you can do whatever you want with it. This should work for most keys including ctrl, shift, spacebar. You could intercept Enter from OnTextCommited when switching on commit method.

This will not work for the arrow keys as they move the caret.

Perhaps there’s a completely different method to achieve what you need. Not enough info to go on.

Yep…Exactly.
I am trying to implement keyboard navigation. I want to change focus to another widget when the user press up arrow key. To do that I need to get the key press event in my parent C++ class associated with the Widget Blueprint.

How to get the character equivalent of EKeys::Space or EKeys::LeftCtrl, etc?

You could create a Map with string *Keys *and eKey *values *(if that sounds confusing, have a look here: Map Containers in Unreal Engine | Unreal Engine 5.3 Documentation).
You’d want to pair the string spat out by the textbox with the eKey equivalent.

Alternatively, you could use Select node and feed it an enumerator.

TMap<FKey,FString> Test;

Test.Add(EKeys::Up,"testvalue");

if(Input.EndsWith(???))
{
    UE_LOG(LogTemp, Warning,TEXT("Space bar clicked"));
}

What should I give as condition?

It’s the other way round:



TMap<FString, FKey> Test;

FKey* PtrMyKey = Test.Find("Left Control");


The Widget needs to have keyboard focus if you want key events to work. Also, make sure your Player Controller input state is set to ‘GameAndUI’

That’s not the problem. The editable box needs the focus, when you type it consumes the input and Key events are not produced anymore, that’s fine, too. OP wants to propagate the input while typing - that’s also fairly easy, as described above.
The only issue I see are the arrow keys, these are used to move the caret of the editable box. Not sure how to work around that.

If you’re using “GameAndUI” input mode, it should still fire regular gameplay events… I think. Been a while since I’ve done that.

Thank you all for your suggestions and comments. Really helpful.

This is the solution that I was looking for.

Really useful post and it worked.

But I am having another problem. When I tried to use multicast delegate, it is showing compilation error…! Why is that? Is there any constrain like, delegates are not allowed to be used in classes that inherits from an interface?

Nowadays solution is easy:

  1. In Widget DESIGNER select root element (same as Widget name) and in Details window set it “Is Focusable”
  2. In Widget GRAPH Override function OnKeyDown in a way like
  3. If Widget has been created in a common way, Esc will show menu and close it back