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:
- return true if key or mouse button pressed
- get position of mouse x and y
- later add event queue for syncing with framerate/loop
I read that events/input can be challenging, just looking for a nudge in the right direction.
P.S. I wouldn't mind using a light weight library that simplifies this with maybe support for touch screens/mobile even controller input.
Mostly for gaming purposes.