Hi,
For ESC key, have you tried simple?
import pyautogui
pyautogui.press(‘esc’)
Works for win file pickers.
In case of the inupt, and what @damies13 wrote, seek for Execute JS solution, that will disable native window opening after click, maybe this thread will help.