Input actions and UI
Skill ferret-input-ui · download all skills · SKILL.md
When to use#
Adding controls, showing a prompt or HUD line, building a menu, testing input.
The model#
A game declares actions (button or axis2) and per-kind bindings (keyboard, console, gamepad, touch). InputService samples every fixed step: down, pressed, released, axis, lookDelta; prompt(a) returns the label of the current binding for UI text. On OS Beroun the cursor, A and B reach the page as keys, so console is an ordinary key map.
Steps#
- Declare
actionsandbindings; pass both tocreateGame. - Use
input.pressed('use')inonFixedUpdate, never raw key codes. - Phones and tablets get
TouchControlsfrom the touch bindings automatically (touchControls: falseto opt out). - UI:
setHud(key, text|null),setPrompt(text),toast(text)(at most three at once),openMenu(def)withMenuModel(up/down/accept/back),pauseMenu. - In tests:
inject(action, value);enabled = falsewhile a menu or cutscene is up.
Check afterwards#
Play every action with each binding kind; open the menu with only cursor, A and B; the prompt text matches the active kind.
What usually goes wrong#
- Binding extra console buttons: apps use the cursor, A (Enter) and B (Exit) only unless the owner allows more.
- Writing menu code that needs a mouse: use
MenuModelso D-pad, A, B, mouse and touch all work. - HUD sizes in pixels instead of
em. - Forgetting to disable input while a menu is open.
Files#
reference/input-ui.md— Actions over every device, on-screen controls for touch, and the HTML overlay for HUD, prompts, toasts and menus.reference/api-input.md— every export of@ferret/inputwith signature and doc commentreference/api-ui.md— every export of@ferret/uiwith signature and doc comment