Is it possible to close UMG widgets with escape?

Ok, I have an UMG widget I want to close when the player clicks on the escape key.

One important thing to note: After I add the widget to the viewport, I call the “SetInputMode UIOnly” in order to have proper mouse focus (to avoid this issue).

Because of that, the usual Action Input Events I have in my character blueprint don’t work anymore.

I found this Thread, in which Darnell said: “In 4.4 input is kind of broken”.
Is this still the case?

How would I utilize the power of UE4 to register a keystroke and close a menu?

Since nobody answered here, I decided to ask the unreal subreddit. Maybe someone there has a clue.

You need to implement an OnKeyDown event within the widget. I’m attaching 2 screens to demonstrate.

First implement the on key down function, then add a check inside the function to determine if the keypress is ESC.

39187-implementfunction.jpg

THANK YOU!

That’s it!

One more comment:

I seem to run into problems when the root widget is a canvas panel. Once I click on it, the function isn’t triggered anymore. But when I wrap the canvas panel in a border widget, everything works fine.

Hey Deventico, I thought perhaps this would solve my issue, but it seems it’s not possible to wrap a root canvas in a border widget…

Your widget must have focus for the function to trigger, uncheck focusable for anything that might steal it like buttons etc, and finally set your root to focusable.

The “On Key Down” function didn’t work for me until I added any keyboard event