How do I write a command to press a key?

How do I make a key press? For example make the key “a” press, with a JavaScript code?

2/11/2020 12:27:32 AM


9 Answers

New Answer


Ginfio what you want to do is called "automation" which i think it's not possible in JavaScript for some reason ( it can't natively interact with the OS )...if you know some Lil syntax in python, I'd suggest you use selenium and automate the game


Hope this helps https://stackoverflow.com/questions/596481/is-it-possible-to-simulate-key-press-events-programmatically I didn't know that...🤔


Calviղ Your code looks like if you're pressing a key but it's an illusion.


<input id="in1" type="text" /> <script> const in1 = document.getElementById('in1'); in1.value = in1.value + 'a'; </script>


What do you mean by "press itself"? What's the purpose of doing that?


Ginfio Just update the input with value property


Ok, it looks like I should explain a little further... On this typing game called "Nitro Type", I'm trying to see if I could attempt to make an auto typer because there isn't a working one at the moment. When you go to race (to type), the text you are gonna type comes up. For example if the first letter is a "D", you press the key "D", if the next letter is a "c", you type "c", ... and so on. So, first I need to know how I can make that "D" (for example) press itself. ... the website: https://www.nitrotype.com/race


Calviղ I mean like: there’s an input and you want to type “b”, you don’t actually physically press the key, but somehow with some code type b in the input. Auto typer.


try updating the input with value property as you are doing but with delay, like using timer so that you can get the visual effect of typing