How to use key only in UMG?

I want to make that I can use key “space” only in UMG

for example: In game , the key “space” is jump. But when I toggled UMG, the key “space” is use item in inventory

First you have to stop the key doing stuff in the game, you can get at that using: Project Settings > Engine > Input

The -I think- ( not at a machine ) you can just add a ‘keyboard space’ event in the UMG BP.

Incidentally, you can use the spacebar in both, because you can set the controller to only look at game input or UMG input: SetInputModeGameOnly and SetInputModeUIOnly will do that… ( pull a pin from ‘get controller’… )

I did what you said, SetInputModeUIOnly won’t allow me to press any keys.

You then have to put the space handling stuff in the widget:

https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/57144-control-widget-with-key-press