2019-06-21 11:33:15 -04:00
|
|
|
use winit::{
|
2019-06-26 23:58:21 -07:00
|
|
|
event::{DeviceEvent, ElementState, Event, KeyboardInput, WindowEvent},
|
2019-06-21 11:33:15 -04:00
|
|
|
event_loop::{ControlFlow, EventLoop},
|
|
|
|
window::WindowBuilder,
|
|
|
|
};
|
2019-02-05 10:30:33 -05:00
|
|
|
|
2018-06-18 12:32:18 -04:00
|
|
|
fn main() {
|
2019-02-05 10:30:33 -05:00
|
|
|
let event_loop = EventLoop::new();
|
2018-06-18 12:32:18 -04:00
|
|
|
|
2019-02-05 10:30:33 -05:00
|
|
|
let window = WindowBuilder::new()
|
2018-06-18 12:32:18 -04:00
|
|
|
.with_title("Super Cursor Grab'n'Hide Simulator 9000")
|
2019-02-05 10:30:33 -05:00
|
|
|
.build(&event_loop)
|
2018-06-18 12:32:18 -04:00
|
|
|
.unwrap();
|
|
|
|
|
2019-02-05 10:30:33 -05:00
|
|
|
event_loop.run(move |event, _, control_flow| {
|
|
|
|
*control_flow = ControlFlow::Wait;
|
2019-06-26 23:58:21 -07:00
|
|
|
match event {
|
|
|
|
Event::WindowEvent { event, .. } => match event {
|
2019-02-05 10:30:33 -05:00
|
|
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
|
|
|
WindowEvent::KeyboardInput {
|
2019-06-21 11:33:15 -04:00
|
|
|
input:
|
|
|
|
KeyboardInput {
|
|
|
|
state: ElementState::Released,
|
|
|
|
virtual_keycode: Some(key),
|
|
|
|
modifiers,
|
|
|
|
..
|
|
|
|
},
|
2018-06-18 12:32:18 -04:00
|
|
|
..
|
|
|
|
} => {
|
2019-02-05 10:30:33 -05:00
|
|
|
use winit::event::VirtualKeyCode::*;
|
2018-06-18 12:32:18 -04:00
|
|
|
match key {
|
2019-02-05 10:30:33 -05:00
|
|
|
Escape => *control_flow = ControlFlow::Exit,
|
2019-05-29 21:29:54 -04:00
|
|
|
G => window.set_cursor_grab(!modifiers.shift).unwrap(),
|
|
|
|
H => window.set_cursor_visible(modifiers.shift),
|
2018-06-18 12:32:18 -04:00
|
|
|
_ => (),
|
|
|
|
}
|
2019-06-24 12:14:55 -04:00
|
|
|
}
|
2018-06-18 12:32:18 -04:00
|
|
|
_ => (),
|
2019-06-26 23:58:21 -07: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-18 12:32:18 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|