Incular logoIncular
API ReferenceInput & Forms

Keyboard & Shortcuts

Key listeners, action listeners, and shortcut bindings with every method.

KeyboardListener

use incular::prelude::*;

fn main() {
    let app = Application::new(|_cx| {
        Container::builder()
            .padding(EdgeInsets::all(24.0))
            .alignment(Alignment::CENTER)
            .child(
                Column::builder()
                    .main_axis_size(MainAxisSize::Min)
                    .spacing(8.0)
                    .children(Vec::<Widget>::from([
                        KeyboardListener::new(Text::new("Type here"))
                                .autofocus(true)
                                .on_key_down(|event| {
                                    println!("down: {event:?}");
                                })
                                .on_key_up(|_event| {}).into(),
                        FocusableActionDetector::new(Text::new("Actions"))
                                .on_focus_change(|has| {
                                    println!("focus: {has}");
                                }).into(),
                    ]))
                    .build(),
            )
            .build()
            .into()
    })
    .expect("valid application");
    incular::run(app).expect("run application");
}
WidgetPurpose
KeyboardListenerRaw key phases with optional shortcuts wiring
ActionListenerListen to action Start/End phases (on_action fires on End)
CallbackShortcutsBind activators directly to callbacks
FocusableActionDetectorFocus + shortcuts + actions with highlight callbacks

on_key runs first (true consumes); with_shortcuts wires a shortcuts + actions pair; focus_node (alias node), autofocus, and include_semantics (default true) configure focus and semantics.

ActionListener

Listens to Start/End phases around a gesture Action; on_action fires on End, with on_action_start / on_action_end for the individual phases.

CallbackShortcuts

Actions<C> is the typed action registry keyed by CommandId; ShortcutActivator binds a trigger to an action id consumed by CallbackShortcuts (shortcut(activator, callback) / shortcuts([(activator, callback)])) and FocusableActionDetector.

FocusableActionDetector

focus_node, enabled (default true), autofocus (default false), shortcuts/actions registries, and on_focus_change / on_show_focus_highlight / on_show_hover_highlight — exercised in the runnable program above.

KeyboardEvent { key: KeyboardKey/NamedKey/Code, modifiers, state: KeyState } — see Desktop.

Intent<C: CommandId> wraps a typed command for the action registry (Intent::new, command()). ShortcutKey { code, modifiers } (physical), LogicalShortcutKey { key, modifiers } (logical), SingleActivator { trigger, modifiers, include_repeats } (new, with_repeats, accepts), ShortcutTrigger: Down (default) / Press / Repeat / Up / Any (matches(event)). ActionInvocationPhase: Start / End; ActionResult: Handled / Ignored (with From<bool>).

Related: Focus.

On this page