Cancel any action on mouse click

Hello!

I’ve had the same issue multiple times, looks like it should be a common problem and I’m just missing an obvious thing.

Situation 1. I have a custom menu - you click a button and it shows. I want to hide the menu, when user clicks anywhere else on the screen except the menu. The best I did so far - create a border widget, covering the entire screen, and catch the events. Ugly, but sort of works.

Situation 2. I have a simple inventory (list of buildings available), and when I click one item, it highlights, I can place the building onto the world, it’s all cool. I want to cancel the selection, when user clicks anywhere else.

I tried the same trick with a huge canvas, returning Unhandled from mouse down events - it will not be delivered to the actors.
I tried to subscribe to all PlayerController mouse events and cancel the action. But if user clicks another button in the UI - there’s no way for me to uniformly listen to all these events. I must put a special code into each button click processor to cancel the active actions. That’s not ideal. So I still don’t have a good enough solution for that.
I tried to play with “game only” and “UI only” modes, they don’t seem to help with it.
I tried to play with widget focus - still not sure how it works and how used (not much documentation available).

So, I guess my question is - can I listen to all mouse events globally, both UI and in game?
Then I can make a delegate and put some custom logic, depending on the current player action.

Or maybe there’s a better way of handling this?