Skip to main content
@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 of InputEnum (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, 0 by default.
  • isButtonJustPressed and isButtonJustReleased are true for one tick only.
  • Small stick movements are reported as 0. Change the threshold with new ControllerLibrary({ deadzone: 0.2 }) (default 0.15).
  • onConnect(listener) and onDisconnect(listener) tell you when a controller is plugged in or out. vibrate(effect) makes it rumble where the browser supports it.