Hide/show cursor triggers incorrectly. (Set input mode)

What i want to happen:
When alt is pressed i can only effect the UI.
When it released it goes back to controlling just the player character.

What actually happens:
When i press alt (ShowMouseCursor) the even triggers as it should.
However as soon as i click anywhere on the UI (with the ShowMouseCursor still pressed) the released action triggers.

I’m well aware this is something im probably doing wrong. im guessing its something to do with the control being taken away from the player controller?

This is what i have inside the player controller.

Can anyone suggest a fix or a tutorial?

Appreciate any help.

I know this isn’t an answer but having a button on the UI would be ideal. Have that button set focus back to the game, hide the mouse and destroy the widget.

I don’t think there is an easy solution for what you’re trying to do.
You have the InputAction in a blueprint (player character) that has its Input disabled as soon as you click/focus the UI, so the InputAction will be released.

You need to find a way to do the input switching (back to the game) with the Widget instead of the player character.