window event keyboard input
This commit is contained in:
parent
9baeb9c19f
commit
5b53dd94cb
|
@ -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) {
|
} => *control_flow = ControlFlow::Exit,
|
||||||
(VirtualKeyCode::Escape, ElementState::Released) => {
|
_ => {}
|
||||||
*control_flow = ControlFlow::Exit
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
},
|
|
||||||
_ => (),
|
|
||||||
},
|
},
|
||||||
|
_ => {}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue