How do I dispatch the a keyboard event with the keycode 81 automatically?

332 views Asked by At

If you use the repl link, Click apes, and then click begin with undefined, you'll see a timer of my first div, #shrimpCook01, start.
If you press the letter q twice the timer of second div, #shrimpCook02, will start.
The objective is two start the timer of the second div when the first div starts by dispatching a keydown event.
The code I have I think is close, but it is not completing this objective. Maybe I'm missing a keyup as well?

Objective-start timer of #shrimpCook02

var element = document.createElement("p");
element.addEventListener('keydown', logKey);
element.dispatchEvent(new KeyboardEvent('keydown',{'key':'q'}));
element.dispatchEvent(new KeyboardEvent('keydown',{'key':'q'}));
console.log(e.key);
0

There are 0 answers