js simulate keyboard input
element.dispatchEvent(new KeyboardEvent("keydown", { key: "e", keyCode: 69, // example values. code: "KeyE", // put everything you need in this object. which: 69, shiftKey: false, // you don't need to include values ctrlKey: false, // if you aren't going to use them. metaKey: false // these are here for example's sake. }));
Here is what the above code is Doing:
1. Create a new KeyboardEvent object.
2. Set the keyCode property to the key you want to simulate.
3. Dispatch the event.