# My buttons lose keyboard focus if a mouse is clicked

**URL:** <https://forums.unrealengine.com/t/my-buttons-lose-keyboard-focus-if-a-mouse-is-clicked/1150836>\
**Category:** UI\
**Tags:** unreal-engine, Widget, question\
**Created:** [May 1, 2023, 3:26pm UTC](https://forums.unrealengine.com/t/my-buttons-lose-keyboard-focus-if-a-mouse-is-clicked/1150836 "2023-05-01T15:26:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve\_Steveson](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Steve\_Steveson](https://forums.unrealengine.com/u/Steve_Steveson)\
**Post date:** [May 1, 2023, 3:26pm UTC](https://forums.unrealengine.com/t/my-buttons-lose-keyboard-focus-if-a-mouse-is-clicked/1150836/1 "2023-05-01T15:26:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [May 2, 2023, 9:11am UTC](https://forums.unrealengine.com/t/my-buttons-lose-keyboard-focus-if-a-mouse-is-clicked/1150836/2 "2023-05-02T09:11:17Z")

</div>

> [@Steve\_Steveson](#):
>
> only answer I’ve found said to brute-force it with a full-screen button in the background

**Nifty**

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

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/5/e/05eff73303fbd549d7543852cded3f6572be62f2.png)

- you could also add `Handled`:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/1/d/b1d864c6981e4d7ae5a71df42b64ca243f400e7b.png)

- set `Input Mode UI Only`

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/7/3/2737452eac2f47f7f0f7e2f56322c35057379a1d.png)

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

---

<div class="post-metadata">

**Author:** ![StevenHammon](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/stevenhammon/32/88719_2.png) [@StevenHammon](https://forums.unrealengine.com/u/StevenHammon)\
**Post date:** [May 2, 2023, 9:37am UTC](https://forums.unrealengine.com/t/my-buttons-lose-keyboard-focus-if-a-mouse-is-clicked/1150836/3 "2023-05-02T09:37:46Z")

</div>

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

> [@Show mouse cursor in BP?](https://forums.unrealengine.com/t/show-mouse-cursor-in-bp/379299):
>
> Hey everyone, I have this problem with the Set Show Mouse Cursor in Blueprints. I have a main menu level and I want to have the cursor for easy interaction but it doesn’t show up. I have a Event BeginPlay node in the level blueprint that connects with the Set Show Mouse Cursor (enabled) and Get Player Controller as target. What I am doing wrong?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [May 2, 2023, 9:48am UTC](https://forums.unrealengine.com/t/my-buttons-lose-keyboard-focus-if-a-mouse-is-clicked/1150836/4 "2023-05-02T09:48:16Z")

</div>

> [@StevenHammon](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![StevenHammon](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/stevenhammon/32/88719_2.png) [@StevenHammon](https://forums.unrealengine.com/u/StevenHammon)\
**Post date:** [May 2, 2023, 9:50am UTC](https://forums.unrealengine.com/t/my-buttons-lose-keyboard-focus-if-a-mouse-is-clicked/1150836/5 "2023-05-02T09:50:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [May 2, 2023, 9:52am UTC](https://forums.unrealengine.com/t/my-buttons-lose-keyboard-focus-if-a-mouse-is-clicked/1150836/6 "2023-05-02T09:52:01Z")

</div>

> [@StevenHammon](#):
>
> I make sure I control my cursor all the time

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

> [@Hide Mouse - Widget Confusion](https://forums.unrealengine.com/t/hide-mouse-widget-confusion/428952):
>
> Ok this is a basic example of the major problem I’m facing. I have absolutely no idea why this Widget Blueprint doesn’t run as intended. I’m almost considering it’s not my fault. The example above fails to hide the mouse after “Hide Mouse” is printed. Does anyone else get a different result when replicating? Thanks for the help in advance, much appreciated.

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.

---

<div class="post-metadata">

**Author:** ![Steve\_Steveson](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Steve\_Steveson](https://forums.unrealengine.com/u/Steve_Steveson)\
**Post date:** [May 2, 2023, 4:01pm UTC](https://forums.unrealengine.com/t/my-buttons-lose-keyboard-focus-if-a-mouse-is-clicked/1150836/7 "2023-05-02T16:01:51Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [May 2, 2023, 5:30pm UTC](https://forums.unrealengine.com/t/my-buttons-lose-keyboard-focus-if-a-mouse-is-clicked/1150836/8 "2023-05-02T17:30:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Steve\_Steveson](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Steve\_Steveson](https://forums.unrealengine.com/u/Steve_Steveson)\
**Post date:** [May 2, 2023, 5:39pm UTC](https://forums.unrealengine.com/t/my-buttons-lose-keyboard-focus-if-a-mouse-is-clicked/1150836/9 "2023-05-02T17:39:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ciberus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ciberus/32/561261_2.png) [@Ciberus](https://forums.unrealengine.com/u/Ciberus)\
**Post date:** [February 11, 2024, 3:52pm UTC](https://forums.unrealengine.com/t/my-buttons-lose-keyboard-focus-if-a-mouse-is-clicked/1150836/10 "2024-02-11T15:52:48Z")

</div>

Hey I found a solution

> [@Common UI and Keyboard ONLY, no Mouse](https://forums.unrealengine.com/t/common-ui-and-keyboard-only-no-mouse/1234750/4):
>
> Btw in case anyone wants to support mouse also, I found a solution and verified it works in production Mostly when you click outside any widget, UI Viewport receives focus, to prevent such behavior. Create button class inherited from UCommonButtonBase with NativeOnFocusChanging // UBBaseCommonButton.cpp class BOGATYR\_API UBBaseCommonButton : public UCommonButtonBase, public IUserObjectListEntry { GENERATED\_BODY() public: #if PLATFORM\_DESKTOP || WITH\_EDITOR virtual void NativeOnFocusCh…
