0
Just wanted to know how do you use keyboard inputs for a code?
Note: Iâm not a pro.
4 Answers
+ 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
})
+ 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!
+ 1
What I mean is if I was to make a game with input so I could move something using arrow keys or wasd.
+ 1
Build your game based on this:
https://code.sololearn.com/WmDpvq022rZX/?ref=app