Triggering a keydown event programmatically in vanilla Javascript
问题 I have an event attached to the window running on keydown . I would like to test this by having a routine (per interval) programmatically hitting a key on the keyboard. The following code doesn't work - but works fine if I'm actually pressing a key on the keyboard. I originally tried: var evt = document.createEvent("KeyboardEvent"); setInterval(function() { evt.initKeyEvent("keydown", true, true, window, false, false, false, false, 13, 13); }, 500); Here's my current keydown event: window