Keyboard and Focus

← Events and Gestures
STRVCT

Keyboard state tracking, modifier-aware key dispatch, and the responder chain for focus management.

Overview

The browser's native keyboard handling has two critical gaps:

  1. keydown and keyup events tell you which key was pressed, but not which other keys are currently held.
  2. DOM focus is element-level without a concept of a view hierarchy responder chain or tab-order routing between custom view containers.

STRVCT addresses both:

  • SvKeyboard Singleton: Tracks global keyboard state and generates modifier-aware method names (e.g. onShiftAKeyDown, onAlternate_D_KeyDown).
  • SvResponderDomView: Layers a responder chain on top of DOM focus to manage focus acquisition, loss, and Tab-key navigation through the view tree.
1. Raw keydown Event key: "A", modifiers: Shift held 2. SvKeyboard Singleton Tracks currently pressed keys & modifiers; Builds method name: "onShiftAKeyDown" 3. Responder Chain (SvResponderDomView) First responder (focused view) receives event; nextKeyView controls Tab-order routing 4. view.onShiftAKeyDown(event) Runs View-specific key handler executes Views handle specific key combinations by implementing named methods; no modifier-flag parsing required.

Modifier-Aware Method Naming Pattern

When a key event fires, SvKeyboard generates a method name following the pattern:

on[Modifiers][KeyName]Key[Down|Up]

Examples:

  • Pressing A with Shift: onShiftAKeyDown(event)
  • Pressing D with Option/Alt and Shift: onAlternate_D_KeyDown(event) (toggles Developer Mode)
  • Pressing Enter: onEnterKeyDown(event)
  • Pressing Escape: onEscapeKeyDown(event)

Platform Modifier Mappings

  • macOS: Command key maps to MetaLeft / MetaRight (onMetaKey...). Option key maps to Alternate (onAlternateKey...).
  • Windows / Linux: Control key maps to Control (onControlKey...). Alt key maps to Alternate (onAlternateKey...).

Responder Chain (`SvResponderDomView`)

SvResponderDomView provides focus management methods across the view tree:

  • acceptsFirstResponder(): Returns true if the view can receive keyboard focus.
  • becomeFirstResponder(): Acquires focus, updates styling, and calls willBecomeFirstResponder().
  • releaseFirstResponder(): Releases focus and calls willReleaseFirstResponder().
  • nextKeyView: References the next view in the tab order, enabling Tab key navigation across view inputs.