- Remove stage-tamagotchi, stage-pocket, server, and engine workspaces with their workflows, addons, and docs - Switch the toolchain from pnpm to bun, replace lockfiles with bun.lock - Rewrite remaining product references to Moeka
1.3 KiB
@proj-airi/input-gamepad
This package reads controllers through the browser Gamepad API. It accepts controllers that expose the W3C standard mapping.
The package converts browser button indices to physical names. For example, button 0 becomes faceBottom. The printed label can be ×, A, or B.
Use the package
import { StandardGamepadMonitor } from '@proj-airi/input-gamepad'
const monitor = new StandardGamepadMonitor({ deadzone: 0.12 })
const stopListening = monitor.onSnapshot((snapshot) => {
if (!snapshot)
return
console.info(snapshot.leftStick, snapshot.buttons.faceBottom)
})
monitor.start()
// Run these operations when the feature closes.
stopListening()
monitor.stop()
When to use it
Use this package directly in framework-independent browser code. It supports buttons, sticks, and analog triggers.
In Vue code, own the polling lifecycle in a composable: create the controller with createGamepadMonitor(), stop it when the component unmounts, and expose the state you need as readonly refs.
Do not use this package for motion sensors, touchpads, lights, or adaptive triggers. Use a device-specific adapter for these features.
The package ignores controllers without the standard mapping. This rule prevents device-specific button indices from entering application code.