window event keyboard input

This commit is contained in:
neurotok 2021-11-09 19:12:51 +01:00 committed by Benjamin Saunders
parent 9baeb9c19f
commit 5b53dd94cb

View file

@ -15,7 +15,7 @@ use std::ffi::{CStr, CString};
use std::ops::Drop; use std::ops::Drop;
use winit::{ use winit::{
event::{DeviceEvent, ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}, event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
event_loop::{ControlFlow, EventLoop}, event_loop::{ControlFlow, EventLoop},
platform::run_return::EventLoopExtRunReturn, platform::run_return::EventLoopExtRunReturn,
window::WindowBuilder, window::WindowBuilder,
@ -187,25 +187,22 @@ impl ExampleBase {
f(); f();
match event { match event {
Event::WindowEvent { Event::WindowEvent {
event: WindowEvent::CloseRequested, ref event,
window_id, window_id,
} if window_id == self.window.id() => *control_flow = ControlFlow::Exit, } if window_id == self.window.id() => match event {
WindowEvent::CloseRequested
Event::DeviceEvent { event, .. } => match event { | WindowEvent::KeyboardInput {
DeviceEvent::Key(KeyboardInput { input:
virtual_keycode: Some(keycode), KeyboardInput {
state, state: ElementState::Pressed,
virtual_keycode: Some(VirtualKeyCode::Escape),
.. ..
}) => match (keycode, state) {
(VirtualKeyCode::Escape, ElementState::Released) => {
*control_flow = ControlFlow::Exit
}
_ => (),
}, },
_ => (), ..
} => *control_flow = ControlFlow::Exit,
_ => {}
}, },
_ => {}
_ => (),
} }
}); });
} }