@nanoforge-dev/input
v3.0.0
Published
NanoForge Engine - Input (keyboard, mouse and controller)
Readme
About
@nanoforge-dev/input is NanoForge's built-in keyboard/mouse input library. It listens to browser keyboard and mouse events and exposes a per-frame snapshot of the current input state on Context.input. Client-only.
Installation
Node.js 26 or newer is required.
npm install @nanoforge-dev/input
yarn add @nanoforge-dev/input
pnpm add @nanoforge-dev/input
bun add @nanoforge-dev/inputExample usage
Register InputLibrary on your client app:
import { InputLibrary } from "@nanoforge-dev/input";
app.use(new InputLibrary());Query the current input state from any library's __run:
import { InputEnum } from "@nanoforge-dev/input";
public override async __run(ctx: Context): Promise<void> {
if (ctx.input.isKeyPressed(InputEnum.Space)) {
player.jump();
}
if (ctx.input.isDragging(InputEnum.MouseLeft)) {
camera.pan(ctx.input.getDragState());
}
const { x, y } = ctx.input.getMousePosition();
}Context.input also exposes getPressedKeys(), getMouseState(), and getWheelState() for scroll input.
Links
Contributing
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
documentation.
See the contribution guide if you'd like to submit a PR.
Help
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to ask questions in discussions.
