How to make a script that will hold down a key for x seconds

I am very new to python, I have been coding in Lua for about 3 years but just the past couple of days I have been learning python, anyways I am trying to make a script that will hold down the “e” key on my keyboard for x seconds. We can say 2 seconds for now. Here is what I have right now.

from pyautogui import*
from time import sleep
sleep(2)
keyDown("e") 
sleep(2) 
keyUp("e") 

The issue with this is it doesn’t actually hold down the “e” key for 2 seconds it just presses it once. Also for some reason it will only work if I am currently typing something. If I haven’t been clear about something please ask questions like I said I am still very new.

Which os are you on? If linux are you using x windows or wayland?

It’s not obvious if pyautogui allows this. You can try:

with pyautogui.hold('e'):
    time.sleep(2)

but I doubt it will work. Even less likely to work:

pyautogui.press('e', interval=2):

See the docs.