Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change "Input" to "ButtonInput" #282

Open
evievevie opened this issue May 19, 2024 · 1 comment
Open

Change "Input" to "ButtonInput" #282

evievevie opened this issue May 19, 2024 · 1 comment

Comments

@evievevie
Copy link

in bevy 0.13, "Res<Input>" should be replaced with "Res<ButtonInput>"

@Cy-a-n
Copy link

Cy-a-n commented May 21, 2024

To add to this: The updated examples on https://bevy-cheatbook.github.io/input/keyboard.html should be:

fn keyboard_input(keys: Res<ButtonInput<KeyCode>>) {
    if keys.just_pressed(KeyCode::Space) {
        // Space was pressed
    }
    if keys.just_released(KeyCode::ControlLeft) {
        // Left Ctrl was released
    }
    if keys.pressed(KeyCode::KeyW) {
        // W is being held down
    }
    // we can check multiple at once with `.any_*`
    if keys.any_pressed([KeyCode::ShiftLeft, KeyCode::ShiftRight]) {
        // Either the left or right shift are being held down
    }
    if keys.any_just_pressed([KeyCode::Delete, KeyCode::Backspace]) {
        // Either delete or backspace was just pressed
    }
}

and

fn keyboard_events(mut key_evr: EventReader<KeyboardInput>) {
    use bevy::input::ButtonState;

    for ev in key_evr.read() {
        match ev.state {
            ButtonState::Pressed => {
                println!("Key press: {:?} ({:?})", ev.key_code, ev.key_code);
            }
            ButtonState::Released => {
                println!("Key release: {:?} ({:?})", ev.key_code, ev.key_code);
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants