This is the idea: to make the escape button equal to clicking the button "cancel" with the mouse.
Think about muscle memory - the escape button is always in the same position on the keyboard. Cancel button is inside dialog boxes that change position.