diff options
Diffstat (limited to 'client/src/window.rs')
-rw-r--r-- | client/src/window.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/client/src/window.rs b/client/src/window.rs index ac90f71..8b3ee9e 100644 --- a/client/src/window.rs +++ b/client/src/window.rs @@ -7,7 +7,7 @@ use winit::{ event::{DeviceEvent, ElementState, WindowEvent}, event_loop::ActiveEventLoop, keyboard::{KeyCode, PhysicalKey}, - window::{Window, WindowAttributes, WindowId}, + window::{CursorGrabMode, Window, WindowAttributes, WindowId}, }; pub struct WindowState { @@ -53,6 +53,14 @@ impl ApplicationHandler for WindowState { if event.repeat { return; } + if event.state == ElementState::Pressed { + match event.physical_key { + PhysicalKey::Code(KeyCode::Escape) => { + win.set_cursor_grab(CursorGrabMode::Locked).unwrap(); + } + _ => (), + } + } sta.delta.move_dir += match event.physical_key { PhysicalKey::Code(KeyCode::KeyW) => Vec3::X, PhysicalKey::Code(KeyCode::KeyS) => Vec3::NEG_X, |