@nanoforge-dev/input reads the player’s input on the client. It has two libraries:
The root
@nanoforge-dev/input exports the keyboard and mouse library too. Register the ones you need with app.use(new InputLibrary()). Both read the current state: call them from a system on every tick.
Keyboard and mouse
Keys and mouse buttons are members ofInputEnum (InputEnum.KeyA, InputEnum.Space, InputEnum.ArrowUp, InputEnum.MouseLeft…). Their values are the browser’s KeyboardEvent.code, so they name a key’s position, not its letter.
Mouse positions use the viewport, so they match the coordinates you draw with.
Controllers
ControllerLibrary reads gamepads with the browser Gamepad API, in the standard layout. Buttons are members of ControllerButton (A, B, X, Y, LeftBumper, Start, DPadUp…), axes of ControllerAxis.
- Each method takes an optional controller index,
0by default. isButtonJustPressedandisButtonJustReleasedare true for one tick only.- Small stick movements are reported as
0. Change the threshold withnew ControllerLibrary({ deadzone: 0.2 })(default0.15). onConnect(listener)andonDisconnect(listener)tell you when a controller is plugged in or out.vibrate(effect)makes it rumble where the browser supports it.