svelte-attach

Gamepad

API docs
import { gamepadButton, isButtonPressed, isSupported } from "@joknoll/svelte-attach/gamepad";

Connect a gamepad and press any button.

Read a button

Face
A
B
X
Y
Shoulders and triggers
LB
RB
LT
RT
Stick clicks
L3
R3
D-pad
UP
DOWN
LEFT
RIGHT
System
SELECT
START
HOME
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>