I'm building a demo with Three.js(even though I want input to work the same way on any library)
I tried researching the subject of user input/events and there are just way to many answers that are using Jquery or some other library or attached to a web element.
I'm just learning so I would like to just stick with Vanilla JS.
I'm just looking for a way that if a keyboard button is pressed example if 'W' pressed then console.log("Key: 'W' was pressed");
Same for mouse input/event mouse position:
console.log(mouseX + ", " + mouseY);
the problem is finding bare bones samples that are vanilla JS. Just looking for a simple solution that I can later build up on for example:
I like to use my own modified version of THREEx.KeyboardState for keyboard input. It's not too complicated - it just subscribes to the keyup and keydown events on the document object and buffers all the events each frame. My game calls the
update method each frame to cycle the buffer.
document.addEventListener("keydown", this._onKeyDown, false); document.addEventListener("keyup", this._onKeyUp, false);