mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-26 22:53:15 -04:00
39 lines
1.3 KiB
Rust
39 lines
1.3 KiB
Rust
extern crate winit;
|
|
|
|
fn main() {
|
|
let events_loop = winit::EventLoop::new();
|
|
|
|
let window = winit::WindowBuilder::new()
|
|
.with_title("Super Cursor Grab'n'Hide Simulator 9000")
|
|
.build(&events_loop)
|
|
.unwrap();
|
|
|
|
events_loop.run(move |event, _, control_flow| {
|
|
*control_flow = winit::ControlFlow::Wait;
|
|
if let winit::Event::WindowEvent { event, .. } = event {
|
|
use winit::WindowEvent::*;
|
|
match event {
|
|
CloseRequested => *control_flow = winit::ControlFlow::Exit,
|
|
KeyboardInput {
|
|
input: winit::KeyboardInput {
|
|
state: winit::ElementState::Released,
|
|
virtual_keycode: Some(key),
|
|
modifiers,
|
|
..
|
|
},
|
|
..
|
|
} => {
|
|
use winit::VirtualKeyCode::*;
|
|
match key {
|
|
Escape => *control_flow = winit::ControlFlow::Exit,
|
|
G => window.grab_cursor(!modifiers.shift).unwrap(),
|
|
H => window.hide_cursor(!modifiers.shift),
|
|
_ => (),
|
|
}
|
|
}
|
|
_ => (),
|
|
}
|
|
}
|
|
});
|
|
}
|