fn
useGamepad
v0.0.15testeddemoReactive wrapper around the Gamepad API. Tracks connected gamepads, emits connection/disconnection events, and polls live button/axis state on every animation frame. The polling loop stays paused while no gamepad is connected and resumes automatically on the first connection, so there is zero idle work. SSR-safe.
Examples
ts
const { gamepads, isSupported, onConnected, onDisconnected } = useGamepad();
onConnected((index) => console.log(`gamepad ${index} connected`));
onDisconnected((index) => console.log(`gamepad ${index} disconnected`));ts
// Map the first gamepad to an Xbox 360 layout
const { gamepads } = useGamepad();
const gamepad = computed(() => gamepads.value[0]);
const controller = mapGamepadToXbox360Controller(gamepad);Demo
Loading demo…
Signature
ts
export function useGamepad(options: UseGamepadOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
options? | UseGamepadOptions | Configuration options |
Returns
UseGamepadReturnReactive gamepad state, lifecycle hooks, and loop controls