Skip to content

Commit

Permalink
examples: Exit when the user presses Escape
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Dec 23, 2023
1 parent a2b40f2 commit ee00a4f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions glutin_examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -165,7 +166,11 @@ pub fn main(event_loop: winit::event_loop::EventLoop<()>) -> Result<(), Box<dyn
}
}
},
WindowEvent::CloseRequested => window_target.exit(),
WindowEvent::CloseRequested
| WindowEvent::KeyboardInput {
event: KeyEvent { logical_key: Key::Named(NamedKey::Escape), .. },
..
} => window_target.exit(),
_ => (),
},
Event::AboutToWait => {
Expand Down

0 comments on commit ee00a4f

Please sign in to comment.