Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close window with escape key #12

Open
trevordblack opened this issue Jul 13, 2024 · 1 comment
Open

Close window with escape key #12

trevordblack opened this issue Jul 13, 2024 · 1 comment

Comments

@trevordblack
Copy link
Collaborator

trevordblack commented Jul 13, 2024

         Event::WindowEvent {
             event: WindowEvent::KeyboardInput { input, .. },
             window_id,
         } if window_id == window.id() => {
             if input.virtual_keycode == Some(VirtualKeyCode::Escape) {
                 *control_flow = ControlFlow::Exit
             }
         }
@armansito
Copy link
Collaborator

armansito commented Jul 13, 2024

In newer versions of winit (0.29) this is done slightly differently:

event_loop.run(|event, control_target| {
        control_target.set_control_flow(ControlFlow::Poll);
        match event {
            Event::WindowEvent { event, .. } => match event {
                WindowEvent::CloseRequested => control_target.exit(),
                ...
            }
        ...

I.e., you can replace *control_flow = ControlFlow::Exit with control_target.exit().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants