forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouse_input_events.rs
49 lines (43 loc) · 1.36 KB
/
mouse_input_events.rs
1
2
3
4
5
6
7
8
9
10
11
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
use bevy::{
input::mouse::{MouseButtonInput, MouseMotion, MouseWheel},
prelude::*,
window::CursorMoved,
};
fn main() {
App::build()
.add_default_plugins()
.init_resource::<State>()
.add_system(print_mouse_events_system.system())
.run();
}
#[derive(Default)]
struct State {
mouse_button_event_reader: EventReader<MouseButtonInput>,
mouse_motion_event_reader: EventReader<MouseMotion>,
cursor_moved_event_reader: EventReader<CursorMoved>,
mouse_wheel_event_reader: EventReader<MouseWheel>,
}
/// This system prints out all mouse events as they come in
fn print_mouse_events_system(
mut state: ResMut<State>,
mouse_button_input_events: Res<Events<MouseButtonInput>>,
mouse_motion_events: Res<Events<MouseMotion>>,
cursor_moved_events: Res<Events<CursorMoved>>,
mouse_wheel_events: Res<Events<MouseWheel>>,
) {
for event in state
.mouse_button_event_reader
.iter(&mouse_button_input_events)
{
println!("{:?}", event);
}
for event in state.mouse_motion_event_reader.iter(&mouse_motion_events) {
println!("{:?}", event);
}
for event in state.cursor_moved_event_reader.iter(&cursor_moved_events) {
println!("{:?}", event);
}
for event in state.mouse_wheel_event_reader.iter(&mouse_wheel_events) {
println!("{:?}", event);
}
}