Function bevy::input::common_conditions::input_just_pressed
pub fn input_just_pressed<T>(
input: T
) -> impl FnMut(Res<'_, ButtonInput<T>>) + Clone
Expand description
Run condition that is active if ButtonInput::just_pressed
is true for the given input.
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, jump.run_if(input_just_pressed(KeyCode::Space)))
.run();
}
Examples found in repository?
examples/tools/scene_viewer/scene_viewer_plugin.rs (line 76)
68 69 70 71 72 73 74 75 76 77 78 79
fn build(&self, app: &mut App) {
app.init_resource::<CameraTracker>()
.add_systems(PreUpdate, scene_load_check)
.add_systems(
Update,
(
update_lights,
camera_tracker,
toggle_bounding_boxes.run_if(input_just_pressed(KeyCode::KeyB)),
),
);
}
More examples
examples/ui/overflow_debug.rs (line 17)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.init_resource::<AnimationState>()
.add_systems(Startup, setup)
.add_systems(
Update,
(
toggle_overflow.run_if(input_just_pressed(KeyCode::KeyO)),
next_container_size.run_if(input_just_pressed(KeyCode::KeyS)),
update_transform::<Move>,
update_transform::<Scale>,
update_transform::<Rotate>,
update_animation,
),
)
.run();
}
examples/2d/sprite_animation.rs (line 19)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest())) // prevents blurry sprites
.add_systems(Startup, setup)
.add_systems(Update, execute_animations)
.add_systems(
Update,
(
// press the right arrow key to animate the right sprite
trigger_animation::<RightSprite>.run_if(input_just_pressed(KeyCode::ArrowRight)),
// press the left arrow key to animate the left sprite
trigger_animation::<LeftSprite>.run_if(input_just_pressed(KeyCode::ArrowLeft)),
),
)
.run();
}
examples/time/virtual_time.rs (line 20)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(
Update,
(
move_virtual_time_sprites,
move_real_time_sprites,
toggle_pause.run_if(input_just_pressed(KeyCode::Space)),
change_time_speed::<1>.run_if(input_just_pressed(KeyCode::ArrowUp)),
change_time_speed::<-1>.run_if(input_just_pressed(KeyCode::ArrowDown)),
(update_virtual_time_info_text, update_real_time_info_text)
// update the texts on a timer to make them more readable
// `on_timer` run condition uses `Virtual` time meaning it's scaled
// and would result in the UI updating at different intervals based
// on `Time<Virtual>::relative_speed` and `Time<Virtual>::is_paused()`
.run_if(on_real_timer(Duration::from_millis(250))),
),
)
.run();
}
examples/games/desk_toy.rs (line 42)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "Bevy Desk Toy".into(),
transparent: true,
#[cfg(target_os = "macos")]
composite_alpha_mode: CompositeAlphaMode::PostMultiplied,
..default()
}),
..default()
}))
.insert_resource(ClearColor(WINDOW_CLEAR_COLOR))
.insert_resource(WindowTransparency(false))
.insert_resource(CursorWorldPos(None))
.add_systems(Startup, setup)
.add_systems(
Update,
(
get_cursor_world_pos,
update_cursor_hit_test,
(
start_drag.run_if(input_just_pressed(MouseButton::Left)),
end_drag.run_if(input_just_released(MouseButton::Left)),
drag.run_if(resource_exists::<DragOperation>),
quit.run_if(input_just_pressed(MouseButton::Right)),
toggle_transparency.run_if(input_just_pressed(KeyCode::Space)),
move_pupils.after(drag),
),
)
.chain(),
)
.run();
}
examples/math/render_primitives.rs (line 25)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
fn main() {
let mut app = App::new();
app.add_plugins(DefaultPlugins)
.init_state::<PrimitiveSelected>()
.init_state::<CameraActive>();
// cameras
app.add_systems(Startup, (setup_cameras, setup_lights, setup_ambient_light))
.add_systems(
Update,
(
update_active_cameras.run_if(state_changed::<CameraActive>),
switch_cameras.run_if(input_just_pressed(KeyCode::KeyC)),
),
);
// text
// PostStartup since we need the cameras to exist
app.add_systems(PostStartup, setup_text);
app.add_systems(
Update,
(update_text.run_if(state_changed::<PrimitiveSelected>),),
);
// primitives
app.add_systems(Startup, (spawn_primitive_2d, spawn_primitive_3d))
.add_systems(
Update,
(
switch_to_next_primitive.run_if(input_just_pressed(KeyCode::ArrowUp)),
switch_to_previous_primitive.run_if(input_just_pressed(KeyCode::ArrowDown)),
draw_gizmos_2d.run_if(in_mode(CameraActive::Dim2)),
draw_gizmos_3d.run_if(in_mode(CameraActive::Dim3)),
update_primitive_meshes.run_if(
state_changed::<PrimitiveSelected>.or_else(state_changed::<CameraActive>),
),
rotate_primitive_2d_meshes,
rotate_primitive_3d_meshes,
),
);
app.run();
}