From ee00a4f61100b124bcd7aace511dd880ead070a4 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Mon, 18 Dec 2023 18:06:31 +0100 Subject: [PATCH] examples: Exit when the user presses `Escape` --- glutin_examples/src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/glutin_examples/src/lib.rs b/glutin_examples/src/lib.rs index 059df51b48..ad2e42dc95 100644 --- a/glutin_examples/src/lib.rs +++ b/glutin_examples/src/lib.rs @@ -4,7 +4,8 @@ use std::num::NonZeroU32; use std::ops::Deref; use raw_window_handle::HasRawWindowHandle; -use winit::event::{Event, WindowEvent}; +use winit::event::{Event, KeyEvent, WindowEvent}; +use winit::keyboard::{Key, NamedKey}; use winit::window::WindowBuilder; use glutin::config::ConfigTemplateBuilder; @@ -165,7 +166,11 @@ pub fn main(event_loop: winit::event_loop::EventLoop<()>) -> Result<(), Box window_target.exit(), + WindowEvent::CloseRequested + | WindowEvent::KeyboardInput { + event: KeyEvent { logical_key: Key::Named(NamedKey::Escape), .. }, + .. + } => window_target.exit(), _ => (), }, Event::AboutToWait => {