i would like to simulate a key press in js. 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.
thank you very much in advance for any help.
EDIT 1:
this should not be considered a dublicate of: Is it possible to simulate key press events programmatically?
because this does not solve my problem. i have already tried it.
EDIT 2:
please do not downvote this question just because you do not know how to answer it.
Best Answer
If you have or can include jQuery, here's the easy way
With jQuery
To simulate the keypress event within an input field, use like this
Without jQuery
The above code infact will not modify the input value for you, it will only simulate keystrokes
See this post for more info How to simulate typing in input field using jQuery?
What you need is : fn.sendKeys