๐น๏ธ Controls
Keyboard
The browserโs keydown and keyup events let you track which keys are pressed. For movement, games typically maintain a set of currently held keys and poll it each frame rather than responding to individual events.
Using event.code (e.g., "KeyW", "Space") instead of event.key avoids layout issues โ a player on an AZERTY keyboard wonโt have W where you expect it. See the i18n keyboard controls guide and the Keyboard.getLayoutMap() API for remapping support.
Mouse
For first-person or camera-rotation controls, the Pointer Lock API captures the cursor and provides raw delta values (movementX, movementY) โ the cursor no longer hits the screen edge.
Scroll events are inconsistent across browsers and devices (trackpads vs. mouse wheels produce wildly different delta values), so normalization is often needed.
Gamepad
The Gamepad API provides access to connected controllers, exposing analog stick values and button states. It is a polling API โ you read navigator.getGamepads() each frame rather than listening to events. Analog sticks have natural drift and need a deadzone threshold applied before use.
Mobile
On touchscreens, virtual joysticks are the most common control scheme. They handle touch events and return normalized direction vectors and force values.
