I don’t think it exists. But even if it did, it wouldn’t help you.
You very quickly run into the scenario where the player can press ESC several times to get out of submenus. Going back to a previous input mode, doesn’t make any sense in that example, because you need to stay in UI, until the player wants to go back to the game.