My buttons lose keyboard focus if a mouse is clicked

I’m trying to make a game menu that uses exclusively keyboard navigation. The problem is, the game is still registering mouse input while the menus are up, and any stray click deselects the UI. The only answer I’ve found said to brute-force it with a full-screen button in the background and store the last focused button as a variable. Is there any way to disable the mouse interaction directly?

Nifty

  • this may work well enough for a widget losing keyboard focus:

image

  • you could also add Handled:

image

  • set Input Mode UI Only

image

  • set pointer position on Tick to be at 0,0 (in the Pawn, perhaps)
  • disable mouse in the Player Controller, set cursor to None
  • set cursor to None for all widgets
  • create a separate channel for the mouse to trace on

A combination of the above may do it.

Player Controller has a built in variable “Show Mouse Cursor” You can 100% control if you see the cursor or not.

This is not true. Cursor visibility control is separate for the player controller and for widgets. Widgets will override pointer visibility when in focus and are themselves visible.

Besides that, OP complained about functionality.

2 Likes

Oh. Weird. Cause I make sure I control my cursor all the time. Sorry. My bad. I just Show the widget I want, and change Input mode however I want. and then set the mouse on or off. All together like that.

The PC has no idea what is happening to the cursor while it’s over widgets:

And every widget decides what the cursors looks like and how it behaves. Unless something dramatic changes in UE5 I’m not aware of, that is.

1 Like

I’ve tried most of these to no avail:
[Event In Focus Lost] doesn’t trigger at all. I suspect this may indicate focus is still in the widget, just not any of the buttons.
The input has been UI only already. This feed into that suspicion further.
Adding [Handled] hasn’t changed anything, as far as I can tell. Click outside buttons still causes loss of focus; clicking inside buttons still activates them.
Setting the cursor to none was only visual.
I created a player controller and disables click events, but that didn’t do anything either. I also changed something called “Default Click Trace Channel” in it. Is that what you were talking about in the last point?

Nah, the controller wouldn’t work here. Not sure if there’s a good solution there for BPs. I’ll poke around tomorrow.

Essentially, we want to disable any and all mouse cursor interaction while a menu is up.

I have no plan to use mouse interaction in the gameplay either, so just disabling it permanently would be fine, too.

1 Like

Hey I found a solution