Binding several actions to same function

How am I supposed to do this?

Let’s say I want to use WASD to move my character around, but then I want W and S to be able to move through menus and its different submenus. How would I make it so I can make the same button not move my character around when I’m inside a menu (something made in UMG for example) and how to avoid the same key to move around my menu and subsequent submenus?

Probably a switch on Enum.

Create an Enum with two entries like ‘Menu’ and ‘Game’, then switch it to ‘Menu’ when you want to open the UMG to activate your different controls.