0

Just wanted to know how do you use keyboard inputs for a code?

Note: I’m not a pro.

22nd Jul 2018, 2:49 AM
The C0der
The C0der - avatar
4 Respostas
+ 5
Yes, you can, you just need the events that I wrote in the previous comment and check for the key something like this.. element.addEventListener('keypress', function(e){ If (e.keyCode == 87) moveUp() //87 is keyCode for W })
22nd Jul 2018, 3:13 AM
Guillem Padilla
Guillem Padilla - avatar
+ 1
I don't exactly understand what do you means... If you are asking about how to manage keyboard inputs in javascript there are some methods: var input = document.getElementById('input') input.addEventListener(document, "keypress", function (e) { console.log("keypress"); }); input.addEvent(document, "keydown", function (e) { console.log("keydown"); }); input.addEventListener(document, "keyup", function (e) { console.log("keyup"); }); Hope it helps you!
22nd Jul 2018, 3:02 AM
Guillem Padilla
Guillem Padilla - avatar
+ 1
What I mean is if I was to make a game with input so I could move something using arrow keys or wasd.
22nd Jul 2018, 3:05 AM
The C0der
The C0der - avatar
+ 1
22nd Jul 2018, 3:24 AM
Calviղ
Calviղ - avatar