{"name":"prefab-input","title":"Input","kind":"prefab","status":"available","summary":"One input API for desktop and mobile: keyboard, or fully customizable virtual controls, any number of buttons/joysticks/d-pads with position, size, shape and short/long-press semantics; same axes/pressed()/onPress() reads either way.","spec":"prefab-input@0.2.0","version":"0.2.0","versions":["0.2.0","0.1.0"],"license":"MIT","source":"prototir","sizeKB":null,"requires":[],"permissions":[],"flags":{"wasm":false,"streamed":false},"compatibility":"Desktop (keyboard) and mobile (touch). On touch devices it draws on-screen controls; multi-touch works, so two sticks can be used at once.","install":{"manifest":"{\n  \"modules\": [\n    \"prefab-input@0.2.0\"\n  ]\n}","importFrom":"prefab-input"},"example":"import { createInput } from 'prefab-input';\n\nconst input = createInput({\n  actions: [{ id: 'jump', key: 'Space', label: 'A' }]\n});\n\nfunction frame() {\n  const { x, y } = input.axes; // -1..1, y = forward\n  if (input.pressed('jump')) player.jump();\n  requestAnimationFrame(frame);\n}\nframe();","api":[{"heading":"createInput(options)","entries":[{"signature":"actions: [{ id, key, label?, position?, size?, shape?, longPressMs? }]","description":"Named actions. `key` is a KeyboardEvent.code such as 'Space' or 'KeyE'. On touch each action becomes a button; `position` is { left | right | top | bottom } in px or CSS lengths, `shape` is 'round' or 'square'."},{"signature":"joystick: true | false | { position?, size?, keys? }","description":"The primary 'move' stick, on by default. WASD and the arrow keys drive it on desktop."},{"signature":"joysticks: [{ id, position?, size?, keys?: { up, down, left, right } }]","description":"Extra sticks, read with axis(id). `keys` gives each one a desktop mapping."},{"signature":"dpad: false | true | { id?, position?, size?, keys? }","description":"A digital 4-way pad writing -1, 0 or 1 into an axis ('move' by default)."},{"signature":"virtual: 'auto' | true | false","description":"Whether to draw on-screen controls. 'auto' shows them on touch devices."},{"signature":"joystickSize: 120, longPressMs: 450, mount: document.body","description":"Default stick size in px, default long-press threshold in ms (actions can override it), and where the overlay is added."}]},{"heading":"The returned input","entries":[{"signature":"input.axes","description":"The 'move' axis: { x, y }, each -1..1."},{"signature":"input.axis(id)","description":"Any stick or d-pad axis by id."},{"signature":"input.pressed(id)","description":"Whether an action is held right now."},{"signature":"input.onPress(id, cb) / onRelease / onShortPress / onLongPress","description":"Edge events, identical for keys and on-screen buttons. A long press fires when the threshold is reached, while still held. Each returns an off() function."},{"signature":"input.virtual","description":"Whether on-screen controls are showing."},{"signature":"input.destroy()","description":"Removes the overlay and every listener."}]}],"notes":["0.2.0 only adds to the 0.1.0 API; 0.1.0 stays servable for prototypes that pinned it."],"upstreamDocs":null,"labs":[]}