Close Widget with key press or gamepad button pressed?

It’s been about 2 weeks and I’m still having issues with this and I’m not sure what to do. I’m trying to have some prompts for like if are you sure you want to quit? “Press Enter or A” but I can’t seem to get it working. I’ve tried the onkeydown function override but not sure if it’s right and I’ve tried getting help a few times but I never got anywhere with it. Any help is appreciated! (In the image that shows get Quit Prompt that’s a reference to the widget that’s inside the main widget. Sorry if it’s confusing

Avoid asking the Player Controller what’s up with the keys as it does not really know what is going on while a widget has focus. If a widget is to intercept a keypress, it’s the widget’s job to figure out which key it is.

*OnKeyDown *returns *InKeyEvent *- sample that instead. Start with this:

It’s also a good idea to set *IsFocusable *flag to *True for *the root element.

Thank you so much!

Just having issues I’m trying to get it so when you press Esc it closes the widget I have it setup but I don’t know where I would plug the Exec in to since the “On Key Down” node can only have one node connected to it

Do you need the widget to be dismissable with both Esc and Enter? You can try this:

This is the widget, when you press enter, it closes the game, when you press esc it sets the widget to hidden

Makes sense. This then:

5291b9b5f489c145304f86d7f103e70f46e92a9c.jpeg
https://forums.unrealengine.com/core/image/gif;base64

edit: ignore what the print strings say, I wasn’t thinking much when typing :|. But it should work fine as is: one action for *Enter *and another for Esc. If you need to work in the gamepad keys here as well, use OR from the previous example.

Thank you so much it’s working

Darn, Just having issues with getting keyboard focus to go back on the other widget after you close the widget.

Player Controller itself is definitely not a widget so this will never work. Is Entry Main a widget you created inside the player controller?

No there is a different widget before the entry main. But the first widget is done in player controller. Here is inside entry main.

If the player controller stores a reference to the widget we see above (the one you’re trying set the focus to?), cast to the player controller first and then get that reference. You were asking the engine to treat the player controller as if it was a widget, it’s not. So Get the Player Controller -> Cast to your custom player controller -> get widget reference (providing you remembered to store it when creating the menu)

Hard to tell for sure since I do not understand how the menus are organised in your project. [HR][/HR]
Also, if you take a closer look at the way the Keyboard Focus is set, you’ll notice that it has 2 blue wires coming in as Target - if one of those wires connects to an execution branch that never runs, you’ll get in trouble; that data might be stale or simply not even exist. Consider calling that Focus node twice, each time for the execution branch it belongs to.

Widgets often allow you to connects things like that, which is both a blessing and a curse.