I would like to simulate a key press in JavaScript. preferably without specifying any element.
The way I would like to do it is to use .focus()
on an input and then simulate a key press like the character "a".
Just the same thing that would happen if I would press the key myself.
Searching through the internet I found no solution. It might have something to do with the combination of the simulated event and an input field. Sometimes I can catch the events, but there is no input present in the input field.
Note that this should not be considered a duplicate of Is it possible to simulate key press events programmatically? because this does not solve my problem. I have already tried it.