I'm trying to come up with a solution to press keys virtually for a typing test. What I want is to get the text and store individual letters in an array and then press all keys with some delay in between each presses.
This is the HTML of the text layout. Imagine it has the word hello
.
<div class="digit-container">
<div>
<span>h</span>
</div>
</div>
<div class="digit-container">
<div>
<span>e</span>
</div>
</div>
<div class="digit-container">
<div>
<span>l</span>
</div>
</div>
<div class="digit-container">
<div>
<span>l</span>
</div>
</div>
<div class="digit-container">
<div>
<span>o</span>
</div>
</div>
This is the JavaScript code I have come up with. I have managed to store these letters in an array.
wordList = document.querySelectorAll(".digit-container > div > span");
wordArray = [];
for (let i = 0; i < wordList.length; i++) {
individualWord = wordList[i].innerHTML;
wordArray.push(individualWord);
}
Now I would like JavaScript to send keypresses for this array of letters { "h", "e", "l", "l", "o" }. Basically when I'm pasting this code and press enter in the console, I would like JavaScript to press "Hello" with a milliseconds of delay in between keystrokes. How can I get JavaScript into press keys?