ConstAttach a keyboard binding. Auto-cleans up when the enclosing scope closes.
// Global — bound to `document`
yield* Keyboard.on("mod+k", () => open.set(true));
// Element-local via ElementRef — auto-rebinds on mount/unmount
yield* Keyboard.on("Escape", () => close(), { target: containerRef });
// Multiple bindings, one handler
yield* Keyboard.on(["ArrowDown", "j"], moveDown, { target: containerRef });
// Custom preventDefault predicate
yield* Keyboard.on("Enter", submit, {
preventDefault: (e) => paletteOpen.value === false,
});
Predicate: preventDefault unless the event target is an editable
element. The default behavior when preventDefault is omitted.
Predicate: preventDefault only when a non-Shift modifier is pressed.
Shift is intentionally excluded — shift+/ produces ? on many
layouts and is often what the user "meant to type."
Public namespace. Exports the
onbinder plus the named predicates usable aspreventDefaultvalues and theisEditableTargethelper.