2019-06-22 01:33:15 +10:00
|
|
|
use winit::{
|
2019-06-27 16:58:21 +10:00
|
|
|
event::{DeviceEvent, ElementState, Event, KeyboardInput, WindowEvent},
|
2019-06-22 01:33:15 +10:00
|
|
|
event_loop::{ControlFlow, EventLoop},
|
|
|
|
window::WindowBuilder,
|
|
|
|
};
|
2019-02-06 02:30:33 +11:00
|
|
|
|
2018-06-19 02:32:18 +10:00
|
|
|
fn main() {
|
2019-02-06 02:30:33 +11:00
|
|
|
let event_loop = EventLoop::new();
|
2018-06-19 02:32:18 +10:00
|
|
|
|
2019-02-06 02:30:33 +11:00
|
|
|
let window = WindowBuilder::new()
|
2018-06-19 02:32:18 +10:00
|
|
|
.with_title("Super Cursor Grab'n'Hide Simulator 9000")
|
2019-02-06 02:30:33 +11:00
|
|
|
.build(&event_loop)
|
2018-06-19 02:32:18 +10:00
|
|
|
.unwrap();
|
|
|
|
|
2019-02-06 02:30:33 +11:00
|
|
|
event_loop.run(move |event, _, control_flow| {
|
|
|
|
*control_flow = ControlFlow::Wait;
|
2019-06-27 16:58:21 +10:00
|
|
|
match event {
|
|
|
|
Event::WindowEvent { event, .. } => match event {
|
2019-02-06 02:30:33 +11:00
|
|
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
|
|
|
WindowEvent::KeyboardInput {
|
2019-06-22 01:33:15 +10:00
|
|
|
input:
|
|
|
|
KeyboardInput {
|
|
|
|
state: ElementState::Released,
|
|
|
|
virtual_keycode: Some(key),
|
|
|
|
modifiers,
|
|
|
|
..
|
|
|
|
},
|
2018-06-19 02:32:18 +10:00
|
|
|
..
|
|
|
|
} => {
|
2019-02-06 02:30:33 +11:00
|
|
|
use winit::event::VirtualKeyCode::*;
|
2018-06-19 02:32:18 +10:00
|
|
|
match key {
|
2019-02-06 02:30:33 +11:00
|
|
|
Escape => *control_flow = ControlFlow::Exit,
|
2019-05-30 11:29:54 +10:00
|
|
|
G => window.set_cursor_grab(!modifiers.shift).unwrap(),
|
|
|
|
H => window.set_cursor_visible(modifiers.shift),
|
2018-06-19 02:32:18 +10:00
|
|
|
_ => (),
|
|
|
|
}
|
2019-06-25 02:14:55 +10:00
|
|
|
}
|
2018-06-19 02:32:18 +10:00
|
|
|
_ => (),
|
2019-06-27 16:58:21 +10:00
|
|
|
},
|
|
|
|
Event::DeviceEvent { event, .. } => match event {
|
|
|
|
DeviceEvent::MouseMotion { delta } => println!("mouse moved: {:?}", delta),
|
|
|
|
DeviceEvent::Button { button, state } => match state {
|
|
|
|
ElementState::Pressed => println!("mouse button {} pressed", button),
|
|
|
|
ElementState::Released => println!("mouse button {} released", button),
|
|
|
|
},
|
|
|
|
_ => (),
|
|
|
|
},
|
|
|
|
_ => (),
|
2018-06-19 02:32:18 +10:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|