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:
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:
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: