Gamepad
API docsimport { gamepadButton, isButtonPressed, isSupported } from "@joknoll/svelte-attach/gamepad";Connect a gamepad and press any button.
Read a button
- Face
- ABXY
- Shoulders and triggers
- LBRBLTRT
- Stick clicks
- L3R3
- D-pad
- UPDOWNLEFTRIGHT
- System
- SELECTSTARTHOME
requestAnimationFrame(function poll() {
held = isButtonPressed("A");
requestAnimationFrame(poll);
});Activate the focused element
Tab to a button, then press its gamepad shortcut. Only the focused button responds.
<button {@attach gamepadButton("A")}>Activate</button>Activate without focus
Press Y to jump. LB and RB switch pages.
<button {@attach gamepadButton("Y", { requireFocus: false })}>Jump</button>