Bevy Engine - How to Read Mouse Position in Bevy

In order to listen to mouse events in Bevy and get the mouse position you need to use the Bevy EventReader. In your system you have to define an argument of type EventReader<MouseMotion> for deltas of movement or EventReader<CursorMoved> for cursor position inside the window. Here below you can find an example:

use bevy::{
    input::mouse::{MouseMotion},
    prelude::*,
    window::CursorMoved,
};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_system(print_mouse_events_system)
        .run();
}
fn print_mouse_events_system(
    mut mouse_event_reader: EventReader<MouseMotion>,
    mut cursor_event_reader: EventReader<CursorMoved>,
) {
    for event in cursor_event_reader.iter() {
        // prints: CursorMoved { id: WindowId(00000000-0000-0000-0000-000000000000), position: Vec2(1269.6, 715.2) }
        println!("{:?}", event);
    }
    for event in mouse_event_reader.iter() {
        // prints: MouseMotion { delta: Vec2(0.0, 1.0) }
        println!("{:?}", event);
    }
}