Input sticking when moving game window at the same time
Bevy version
0.6
Operating system & version
Windows 11
What you did
I applied input while moving the game window around at the same time, then released the input key.
What you expected to happen
Input should stop being applied after releasing input.
What actually happened
The input was still being applied even after releasing the key while moving the game window.
Additional information
This is the player movement system I was using when I came across this bug.
fn move_player(
keyboard_input: Res<Input<KeyCode>>,
time: Res<Time>,
mut q_player: Query<(&Player, &mut Transform)>,
) {
let (_, mut transform) = q_player.single_mut();
let key = keyboard_input.get_pressed().next();
let speed = 200.0;
if let Some(ref key) = key {
match key {
KeyCode::A => transform.translation.x -= speed * time.delta_seconds(),
KeyCode::D => transform.translation.x += speed * time.delta_seconds(),
KeyCode::W => transform.translation.y += speed * time.delta_seconds(),
KeyCode::S => transform.translation.y -= speed * time.delta_seconds(),
_ => (),
}
}
}
This is almost certainly a bug in either winit itself, or our interface with it. The next step for this issue is attempting to reproduce this with just winit.
Do you mean trying to reproduce with winit outside of a bevy project? I can go down the rabbit hole if you'd like.
Do you mean trying to reproduce with winit outside of a bevy project? I can go down the rabbit hole if you'd like.
Precisely. If you're in the mood, that would be great.
Not sure of the quality of this example as I've never dealt with winit directly, but if what I did was correct, it doesn't seem to be an issue with winit.
use winit::event::{self, Event, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::WindowBuilder;
fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
event_loop.run(move |ev, _target, flow| {
*flow = ControlFlow::Wait;
match ev {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
window_id,
} if window_id == window.id() => *flow = ControlFlow::Exit,
Event::WindowEvent { event, .. } => match event {
WindowEvent::KeyboardInput {
device_id,
input: kin,
is_synthetic: _,
} => {
println!("WindowEvent Key: {:?} DeviceId: {:?}", kin, device_id);
}
_ => {}
},
Event::DeviceEvent { event, device_id } => match event {
event::DeviceEvent::Key(kin) => {
println!("DeviceEvent Key: {:?} DeviceId: {:?}", kin, device_id);
}
_ => {}
},
_ => {}
}
});
}
When I move the game window while holding down a key, then release, it logs that it has released.
I think we should probably just release all inputs when window focus is lost. Ideally when leaving, but at least when returning.
Input seems to be releasing when losing focus, but when I move the window around and release input, it doesn't register the release.
