Skip to main content

Input

Input

Input is a static runtime input state hub used by controllers.

It tracks keyboard, mouse, wheel, and pointer data, then exposes frame-based getters and helpers.

In normal usage you do not initialize it manually.
Scene / input manager registers surfaces and controls lifecycle.

Core Types

InputEventInfo

FieldTypeDescription
typeevent unionInput event type emitted through onInput(...).
keyCodeKeyCodePresent for keyboard events.
mouseButtonnumberPresent for mouse/pointer button events.

Supported type values:

"keydown" | "keyup"
| "mousedown" | "mouseup" | "mousemove"
| "mouseenter" | "mouseleave"
| "wheel"
| "pointerdown" | "pointermove" | "pointerup" | "pointercancel"
| "pointerenter" | "pointerleave" | "pointerover" | "pointerout"
| "gotpointercapture" | "lostpointercapture"

InputOptions

OptionDefaultDescription
preventAltDefaultfalseCalls preventDefault() for Alt-modified key events (when cancelable).
preventContextMenufalsePrevents browser context menu on registered surfaces.
preventWheelDefaultfalsePrevents browser wheel default behavior (scroll/zoom) on registered surfaces.
usePointerCapturetrueUses pointer capture in pointer down/up flow.

Integration API

APIReturnsDescription
onInput(callback)voidSubscribes one global callback to raw input event stream (InputEventInfo).
configure(options)voidUpdates runtime input options (InputOptions).

Common reads inside controllers

import { Input, MouseButton, KeyCode } from '@flowscape-ui/core-sdk';

const scroll = Input.mouseScrollDelta;
const pointer = Input.mousePosition;
const pointerDelta = Input.mousePositionDelta;

const isPanning = Input.getMouseButton(MouseButton.Right);
const pressedCtrl = Input.ctrlPressed;
const zoomShortcut = Input.getKeyDownCombo(KeyCode.LeftControl, KeyCode.Equals);

Keyboard Getters

GetterTypeDescription
inputStringstringTyped characters collected from keydown in current frame.
anyKeybooleanAny key currently held.
anyKeyDownbooleanAny key pressed this frame.
ctrlPressedbooleanLeft or right Control is held.
shiftPressedbooleanLeft or right Shift is held.
altPressedbooleanLeft or right Alt is held.
metaPressedbooleanCommand/Windows key is held.
isAnyModifierPressedbooleanAny modifier key is held.

Mouse and Wheel Getters

GetterTypeDescription
mousePositionVector2Current mouse position in client coordinates.
mousePositionDeltaVector2Accumulated per-frame mouse delta.
mousePositionDeltaNormalizedVector2Normalized version of mouse delta.
mouseScrollDeltaVector2Wheel delta for current frame.
mouseScrollXnumberWheel X delta.
mouseScrollYnumberWheel Y delta.
mouseInsidebooleanMouse is currently inside registered surface.
anyMouseButtonbooleanAny mouse button currently held.
anyMouseButtonDownbooleanAny mouse button pressed this frame.
scrollCtrlbooleanCtrl state captured from latest wheel event.
scrollShiftbooleanShift state captured from latest wheel event.
scrollAltbooleanAlt state captured from latest wheel event.
scrollMetabooleanMeta state captured from latest wheel event.
cursorstringCurrent cursor string applied to registered surfaces.

Pointer Getters

GetterTypeDescription
pointerPositionVector2Current pointer position in client coordinates.
pointerDeltaVector2Per-frame pointer delta.
pointerDownbooleanPointer is down.
pointerInsidebooleanPointer is inside surface.
pointerCapturedbooleanPointer is currently captured by surface.
pointerType"mouse" | "pen" | "touch"Active pointer type.
pointerPressurenumberCurrent pointer pressure.
activePointerIdnumber | nullActive pointer id or null.
coalescedEventsReadonlyArray<PointerEvent>Coalesced pointer events from latest pointer move.
predictedEventsReadonlyArray<PointerEvent>Predicted pointer events from latest pointer move.

Keyboard Methods

APIReturnsDescription
getKey(key)booleanKey is currently held.
getKeyDown(key)booleanKey pressed this frame.
getKeyUp(key)booleanKey released this frame.
getKeyCombo(...keys)booleanAll keys are currently held.
getKeyDownCombo(...keys)booleanCombo active and at least one key pressed this frame.
getKeyRepeat(key, options?)booleanRepeat helper with delay and interval.
onceKeyDown(key, callback)voidOne-shot callback on next keydown for given key.
getKeyDownOnce(key)booleanAlias of getKeyDown(key).

Mouse Methods

APIReturnsDescription
getMouseButton(button)booleanMouse button is currently held.
getMouseButtonDown(button)booleanMouse button pressed this frame.
getMouseButtonUp(button)booleanMouse button released this frame.
getMouseButtonPressOrigin(button)Vector2Position captured at mousedown for that button.
getMouseButtonHoldDuration(button)numberHold duration in milliseconds.
getMouseDragDelta(button)Vector2Delta from mousedown origin to current mouse position.
getMouseDragDistance(button)numberDistance from mousedown origin.
isMouseButtonHeld(button, duration)booleanButton held at least duration ms.
getMouseButtonClickCount(button, threshold?)numberSequential click count within threshold.
getMouseButtonDoubleClick(button, threshold?)booleanTrue on frame where double-click is detected.
getMouseButtonTripleClick(button, threshold?)booleanTrue on frame where triple-click is detected.
setCursor(value)voidSets cursor for all registered surfaces.
resetCursor()voidResets cursor to default.

Pointer and General Methods

APIReturnsDescription
lockPointer(element)voidRequests pointer lock on element.
unlockPointer()voidExits pointer lock.
isPointerLockedbooleanWhether pointer lock is active.
getModifiers(){ ctrl, shift, alt, meta }Snapshot of current modifier keys.
getAxisValue(neg, pos)numberAxis helper (-1, 0, 1) from two keys.
getVector(left, right, up, down)Vector2Normalized 2D direction from four keys.
isIdle(timeout)booleanNo input detected longer than timeout (ms).

Engine Lifecycle (Internal)

These methods are engine internals (prefixed with _) and are managed by scene/input systems.

Internal APIDescription
_initialize()Registers global listeners (keydown, keyup, blur).
_registerSurface(surface)Attaches mouse/pointer/contextmenu listeners to a surface.
_unregisterSurface(surface)Detaches listeners from a surface.
_destroy()Full teardown of listeners and cached state.
_endFrame()Clears frame-only states (Down/Up, deltas, input string, coalesced/predicted events).

Frame Model

Input has two state types:

  • persistent until changed: getKey, getMouseButton, pointerDown, positions
  • one-frame state: getKeyDown, getKeyUp, mousePositionDelta, mouseScrollDelta, inputString

One-frame state is reset in _endFrame().

Configuration Example

Input.configure({
preventContextMenu: true,
preventWheelDefault: true,
usePointerCapture: true,
});

Typical case: wheel is used for canvas zoom, browser scroll is disabled on surface.

Current Constraints

  • Input tracks both Mouse and Pointer flows in parallel.
  • Active pointer state is single-pointer (activePointerId), not full multi-touch map.
  • inputString is shortcut/simple typing focused (not IME-complete text input).
  • Scroll modifier getters (scrollCtrl, etc.) reflect wheel-event modifiers, not global key state.

Practical rules

  • Read Input inside controllers/modules, not directly in random UI components.
  • Keep browser-behavior toggles (preventWheelDefault) explicit and centralized.
  • Treat Input as state source, and keep interaction decisions in controllers.

Next