Download

UMG Menu Detect KeyDown when not focused

I’m trying to implement a simple action menu in UMG that does not disrupt running/aiming and allows the user to choose from 10 options with their number keys 0-9.

I created a menu in UMG with a C++ subclass that listens for key strokes. Originally I showed the menu with FInputModeGameAndUI but this had the issue of showing the cursor and blocking movement.

Instead I’ve left the InputMode to Game and rerouted the keydown strokes from the playerController to the UMG menu. This works but it requires me to setup 10 functions to BindAction to for each key.

Is there an easier way to accomplish this in UMG? Some sort of ‘ListenForKeyStrokesWhenNotFocused’?

What you’re doing sounds best already. Even if you pass the keycode of each key entered into a single function that uses a switch statement to determine the event to take place in the umg menu, it’s the same thing.

That capability does not exist in UMG. Your two options are to do what you’re doing or to create One Widget to rule them all. Your One Widget would exist at the root of the widget tree and would eventually receive all bubbled up input events before they reached the game.

Doing what you’re doing now is the better approach, UMG lacks the ability to BindActions, and you’d only be able to process input in the raw form, which you never want to do unless you can lookup the action mapping. Because UI systems require a bubbling up input approach, otherwise who has priority when a key is pressed, how does anyone “handle” it in such a free for all.

What we’ve considered doing is making an extra flag on input events similar to “Fire even when paused”, that would allow “Fire even when in UI Only Mode”. Would let you build that modal input screen and just have a single key binding that can flip it on and off.

Please do… I’ve had to add a bit of complexity around the player controller & pawns to allow for key presses to pass to UI while disallowing the pawn from getting input.

I’m dreaming now, but I’d love to see something like a handler for input contexts, similar to this unity plugin. Right now in my game, “Attack” becomes “Paddle” becomes “Confirm Selection” based on in game context, and any remapping for one effects all, so say a player wanted to map different buttons to those functions, they’re out of luck.