Keybind to toggle on a UI screen

i need a way to use a keybind to open a UI screen, similar to how an inventory system in other games works, i want ESC to also function as a way to exit the UI screen, how would i do that?