Handle Key Binds depending on UI and Game mode only

I have a serie of key binds that have different behavior depending on whether the UI is in focus or not.

The scenario, to make myself clearer, is one where we try to use quick items in an adventure game: press button 1 while input mode is “Game only” and the character will equip the item assigned to button 1, press button 1 while you’re navigating your inventory (input mode is “UI only”), and you’ll mark the selected item as your QuickItem for button 1.

However, the only way I managed to achieve this is the following:

  • Create the keybind in my c++ code:
void AProtagonistCharacter::EquipQuickItem(QuickItem selectedItem)
{
    UE_LOG(LogTemp, Display, TEXT("You're trying to equip the quick item"));
}
  • In the UserWidget, I override the OnKeyDown method so that if button 1 is pressed, a different behavior will be triggered

This, however, seems impractical to say the least. I have about 6 keyboard inputs that need to be used in the UI (for example, the button to open the inventory is the same to also close the inventory) and since I can’t even use a switch case for keyboard inputs in blueprint, I’d need to get the string name of the clicked key and then put that string in a switch case.
It’s messy.

I was hoping to override the Action Binding inside my UserWidget like this
image
But what happens is that now only the Widget version of the input will be called, regardless of whether or not the widget itself is in focus.

Is there an elegant way to achieve my goal?

How about this: