From 5b53dd94cbd19dfcdf2dc0f48ae003ad66bd2651 Mon Sep 17 00:00:00 2001 From: neurotok Date: Tue, 9 Nov 2021 19:12:51 +0100 Subject: [PATCH] window event keyboard input --- examples/src/lib.rs | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/examples/src/lib.rs b/examples/src/lib.rs index 6ac8f99..314411b 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -15,7 +15,7 @@ use std::ffi::{CStr, CString}; use std::ops::Drop; use winit::{ - event::{DeviceEvent, ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}, + event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}, event_loop::{ControlFlow, EventLoop}, platform::run_return::EventLoopExtRunReturn, window::WindowBuilder, @@ -187,25 +187,22 @@ impl ExampleBase { f(); match event { Event::WindowEvent { - event: WindowEvent::CloseRequested, + ref event, window_id, - } if window_id == self.window.id() => *control_flow = ControlFlow::Exit, - - Event::DeviceEvent { event, .. } => match event { - DeviceEvent::Key(KeyboardInput { - virtual_keycode: Some(keycode), - state, + } if window_id == self.window.id() => match event { + WindowEvent::CloseRequested + | WindowEvent::KeyboardInput { + input: + KeyboardInput { + state: ElementState::Pressed, + virtual_keycode: Some(VirtualKeyCode::Escape), + .. + }, .. - }) => match (keycode, state) { - (VirtualKeyCode::Escape, ElementState::Released) => { - *control_flow = ControlFlow::Exit - } - _ => (), - }, - _ => (), + } => *control_flow = ControlFlow::Exit, + _ => {} }, - - _ => (), + _ => {} } }); }