Fix the multi-window example handling every key event (#2589)

This commit is contained in:
marc0246 2024-10-22 17:13:02 +02:00 committed by GitHub
parent 50b3b7a42f
commit 43a298e1ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -45,6 +45,7 @@ use winit::{
application::ApplicationHandler, application::ApplicationHandler,
event::{ElementState, KeyEvent, WindowEvent}, event::{ElementState, KeyEvent, WindowEvent},
event_loop::{ActiveEventLoop, EventLoop}, event_loop::{ActiveEventLoop, EventLoop},
keyboard::{Key, NamedKey},
window::{Window, WindowId}, window::{Window, WindowId},
}; };
@ -52,6 +53,8 @@ fn main() -> Result<(), impl Error> {
let event_loop = EventLoop::new().unwrap(); let event_loop = EventLoop::new().unwrap();
let mut app = App::new(&event_loop); let mut app = App::new(&event_loop);
println!("\nPress space to open a new window");
event_loop.run_app(&mut app) event_loop.run_app(&mut app)
} }
@ -365,6 +368,7 @@ impl ApplicationHandler for App {
WindowEvent::KeyboardInput { WindowEvent::KeyboardInput {
event: event:
KeyEvent { KeyEvent {
logical_key: Key::Named(NamedKey::Space),
state: ElementState::Pressed, state: ElementState::Pressed,
.. ..
}, },