Help me setup the keyboard shortcuts on widget

Hello!

I need to do some inventory stuff when we have the current widget is on the screen.

So i have call to the widget and add it on the viewport and set focus on it (I wonder what this"focus" technically means xd)

This OnKeyUp event i have inside the widget. It is focusable. And it simply didn’t work.

I deleted the Set UI Input Only node and everything worked. This is strange considering that the focus is on this very node with the event. But i need this UI Only input. Smth strange is going on =_=

Most of the time you’ll have the Player Controller and Widgets competing for player input. And you have some input modes:

  • Game Only - only player controller can respond (most fps games until you enter inventory where we switch to UI Only)
  • Game and UI - UI has input priority, if unhandled, the PC gets to process it (an action RPG game, the character runs around and you click buttons on the interface)
  • UI Only - only widgets process input (a puzzle game where there’s no player controller needed at all)

In Game and UI, the widget with Focus gets to act first when you press a key. You may have more than one wanting to process input so you may give one Focus. Imagine you have 5 windows and you want to delete the one the cursor is over. Each window overrides onKeyDown for the Del key. So which one will process it? The one you set Keyboard Focus to onMouseEnter.

Sometimes you want widgets clickable but you don’t want them to steal focus from something else:

339710-screenshot-1.png

And some widgets can clear focus once you stop using them, once you’re done with typing text and hit enter, you’re probably no longer need focus on this element:

339711-screenshot-2.png

And some elements steal focus so well that it gets annoying - Buttons! Click a button and the owning widget has focus all of a sudden.


This OnKeyUp event i have inside the
widget. It is focusable. And it simply
didn’t work.

Focus does not persist and widgets lose focus it easily. When unprocessed input reaches player controller = widget no longer has focus. Another widget gained focus, other widgets lost it. Set focus first and onKeyUp will work.

  • give widget focus on click (or any other way):

  • the onKeyDown will trigger:

339715-screenshot-4.png

339716-screenshot-11.png

And most importantly, when the widget has focus and is getting keypresses, the PC has no idea what is going on. So don’t even bother… The widget knows what’s up / down (pun intended).

But i need this UI Only input.

Add this:

339731-screenshot-2.png

So Up can be processed:

While not technically necessary, it helps isolating how the input bubbles. Should work fine with UI only for as long as the focus is set to that widget:

I’ll try it right now. Can you explain how is working Handled/Unhandled node?
I think maybe this is part of the reason, why it is can’t work properly.

  • Handled: I have input, I’m using it, no one else can have it.

If you click on a Button, it will consume / handle the click so your character will not go to the world location underneath the button). The same will happen when you pass Handled.

  • Unhandled: I am happy for someone else to process this input once I’m done with it.

If you stack 2 widgets on top of each other and the top one Unhandles the click, the widget underneath will get a chance to process it, too. If it passes Unhandled as well, the click will go through and search for other entities that can handle it.

If no other widgets are found, it will go to the Player Controller. If the PC does nothing, it terminates. (Game & UI mode)

In the example above, pressing 1 will not notify anything else apart from that widget (the widget Handled it, we’re done with pressing 1). Pressing anything else will notify other blueprints that can process input.


It’s somewhat similar to Consume Input:

339735-screenshot-5.png

Consume / Handled means it’s been used up.