Skip to main content
OpenTUI provides comprehensive input handling with structured key events, modifier support, and mouse interactions including clicks, drags, and scrolling.

Keyboard Input

Basic Key Events

Listen for key presses using the keyInput event emitter:

KeyEvent Properties

The KeyEvent object contains detailed information about the key press:

Common Key Names

Keyboard Shortcuts

Detecting Modifier Combinations

Check for keyboard shortcuts by combining key names with modifiers:

Building a Shortcut System

Create a reusable shortcut handler:

Focus Management

Components like Input and Select need focus to receive keyboard events.

Manual Focus Control

Auto-Focus with Mouse

By default, clicking on a focusable element focuses it. Disable with:

Paste Events

Handle pasted content separately from regular keypresses:

Mouse Events

Mouse Event Types

OpenTUI supports various mouse interactions:

Handling Mouse Events

Override onMouseEvent in custom renderables:

Button Example

Create an interactive button with hover and click effects:

Drag and Drop

Implement draggable elements:

Scroll Handling

Handle mouse wheel scrolling:

Input Components

Built-in components handle their own keyboard input when focused.

InputRenderable

SelectRenderable

Navigate with arrow keys (up/k, down/j) and select with Enter:

TabSelectRenderable

Navigate with left/right arrows (or [/]) and select with Enter:

Complete Example: Navigation Menu

Best Practices

Components should only handle input when focused:
Prevent events from bubbling when handled:
Always show when elements are focused or hovered:

Next Steps

Console Overlay

Debug with the built-in console

Animations

Animate properties smoothly