Go to Settings > Customize Toolbars > Keys and create a new Viewer Hotkey:
Since Esc is special, you'll need to use the menu on the right of the hotkey field to specify it:
Click Advanced in the command editor to put it into multi-line mode.
Use this as the command:
@if:Show VIEWERCMD=fullscreen
Show VIEWERCMD=fullscreen
@if:else
Show VIEWERCMD=close
(Details also copied to Viewer: Exit full screen mode with Esc key in the Buttons/Scripts area, so it's easier to find.)