|
1 | 1 | use std::io::{stdin, stdout, Write};
|
2 | 2 |
|
3 | 3 | use simple_logger::SimpleLogger;
|
4 |
| -use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}; |
| 4 | +use winit::event::{ElementState, Event, KeyEvent, WindowEvent}; |
5 | 5 | use winit::event_loop::{ControlFlow, EventLoop};
|
| 6 | +use winit::keyboard::Key; |
6 | 7 | use winit::monitor::{MonitorHandle, VideoMode};
|
7 | 8 | use winit::window::{Fullscreen, WindowBuilder};
|
8 | 9 |
|
@@ -38,30 +39,33 @@ fn main() {
|
38 | 39 | Event::WindowEvent { event, .. } => match event {
|
39 | 40 | WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
40 | 41 | WindowEvent::KeyboardInput {
|
41 |
| - input: |
42 |
| - KeyboardInput { |
43 |
| - virtual_keycode: Some(virtual_code), |
44 |
| - state, |
| 42 | + event: |
| 43 | + KeyEvent { |
| 44 | + logical_key: key, |
| 45 | + state: ElementState::Pressed, |
45 | 46 | ..
|
46 | 47 | },
|
47 | 48 | ..
|
48 |
| - } => match (virtual_code, state) { |
49 |
| - (VirtualKeyCode::Escape, _) => *control_flow = ControlFlow::Exit, |
50 |
| - (VirtualKeyCode::F, ElementState::Pressed) => { |
| 49 | + } => match key { |
| 50 | + Key::Escape => *control_flow = ControlFlow::Exit, |
| 51 | + |
| 52 | + // WARNING: Consider using `key_without_modifers()` if available on your platform. |
| 53 | + // See the `key_binding` example |
| 54 | + Key::Character("f") => { |
51 | 55 | if window.fullscreen().is_some() {
|
52 | 56 | window.set_fullscreen(None);
|
53 | 57 | } else {
|
54 | 58 | window.set_fullscreen(fullscreen.clone());
|
55 | 59 | }
|
56 | 60 | }
|
57 |
| - (VirtualKeyCode::S, ElementState::Pressed) => { |
| 61 | + Key::Character("s") => { |
58 | 62 | println!("window.fullscreen {:?}", window.fullscreen());
|
59 | 63 | }
|
60 |
| - (VirtualKeyCode::M, ElementState::Pressed) => { |
| 64 | + Key::Character("m") => { |
61 | 65 | let is_maximized = window.is_maximized();
|
62 | 66 | window.set_maximized(!is_maximized);
|
63 | 67 | }
|
64 |
| - (VirtualKeyCode::D, ElementState::Pressed) => { |
| 68 | + Key::Character("d") => { |
65 | 69 | decorations = !decorations;
|
66 | 70 | window.set_decorations(decorations);
|
67 | 71 | }
|
|
0 commit comments