rx_bevy_observable_keyboard

Crates.iorx_bevy_observable_keyboard
lib.rsrx_bevy_observable_keyboard
version0.3.1
created_at2026-01-19 07:03:37.481687+00
updated_at2026-01-24 17:58:14.007393+00
descriptionrx_bevy keyboard observable
homepagehttps://github.com/AlexAegis/rx_bevy
repositoryhttps://github.com/AlexAegis/rx_bevy
max_upload_size
id2053886
size136,709
Sandor (AlexAegis)

documentation

https://github.com/AlexAegis/rx_bevy

README

observable_keyboard

crates.io ci codecov license

The KeyboardObservable turns Bevy keyboard input events into signals. The events are sourced from the ButtonInput<KeyCode> resource.

Options

KeyCode signals can be observed in multiple modes:

  • KeyboardObservableEmit::JustPressed - emits once when the key is pressed down.
  • KeyboardObservableEmit::JustReleased - emits once when the key is released.
  • KeyboardObservableEmit::WhilePressed - emits continuously while the key is held down.

See Also

Example

cargo run -p rx_bevy --example observable_keyboard_example
fn main() -> AppExit {
    App::new()
        .add_plugins((
            DefaultPlugins,
            RxPlugin,
            RxSchedulerPlugin::<Update, Virtual>::default(),
        ))
        .add_systems(Startup, setup)
        .add_systems(
            Update,
            (
                send_message(AppExit::Success).run_if(input_just_pressed(KeyCode::Escape)),
                unsubscribe.run_if(input_just_pressed(KeyCode::Space)),
            ),
        )
        .run()
}

fn unsubscribe(mut example_entities: ResMut<MySubscriptions>) {
    example_entities.subscription.unsubscribe();
}

#[derive(Resource)]
struct MySubscriptions {
    subscription: SharedSubscription,
}

fn setup(mut commands: Commands, rx_schedule_update_virtual: RxSchedule<Update, Virtual>) {
    let subscription = KeyboardObservable::new(default(), rx_schedule_update_virtual.handle())
        .subscribe(PrintObserver::new("keyboard"));

    commands.insert_resource(MySubscriptions {
        subscription: SharedSubscription::new(subscription),
    });
}

Output when pressing WASD keys and Space:

keyboard - next: KeyW
keyboard - next: KeyA
keyboard - next: KeyS
keyboard - next: KeyD
keyboard - next: Space
keyboard - unsubscribed
Commit count: 652

cargo fmt