Skip to content

input::keyboard::ElementState used to handle mouse event #687

@smokku

Description

@smokku

If I want a system reacting on a mouse button press, it looks like this:

use bevy::{
    input::{keyboard::ElementState, mouse::MouseButtonInput},
    prelude::*,
};

fn mouse_click(
    mut state: ResMut<State>,
    mouse_button_input_events: Res<Events<MouseButtonInput>>,
) {
    for event in state
        .mouse_button_event_reader
        .iter(&mouse_button_input_events)
    {
        if event.state == ElementState::Pressed {

It is odd to have to use ElementState from input::keyboard to handle input::mouse event.
I needed to "search all files" on Bevy repo to find out where I need to import this symbol from.

Should we move it to bevy::input?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-InputPlayer input via keyboard, mouse, gamepad, and moreC-FeatureA new feature, making something new possible

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions