From 5f9984df12d106e8e20f67deec34531549000a71 Mon Sep 17 00:00:00 2001 From: Adam Blanchet Date: Wed, 16 Dec 2020 10:40:08 +0100 Subject: [PATCH] working towards #861 - Use scancodes for (at minimum) key remapping added ScanCode fallback for when winit doesn't provide a VirtualKeyCode renamed SKey to ScanKey --- CHANGELOG.md | 1 + voxygen/src/window.rs | 75 ++++++++++++++++++++++--------------------- 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da674ffef9..b7274ce324 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Reflective LoD water - Map indicators for group members - Hot-reloading for i18n, sounds, loot lotteries, and more +- Initial support for alternate style keyboards ### Changed diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index b898254864..664ab3f735 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -311,6 +311,7 @@ pub type EventLoop = winit::event_loop::EventLoop<()>; pub enum KeyMouse { Key(winit::event::VirtualKeyCode), Mouse(winit::event::MouseButton), + ScanKey(winit::event::ScanCode), } impl fmt::Display for KeyMouse { @@ -487,6 +488,7 @@ impl fmt::Display for KeyMouse { Mouse(MouseButton::Other(button)) => // Additional mouse buttons after middle click start at 1 return write!(f, "M{}", button + 3), + ScanKey(_) => "Unknown", }) } } @@ -992,47 +994,48 @@ impl Window { return; } - if let Some(key) = input.virtual_keycode { - if let Some(game_inputs) = Window::map_input( - KeyMouse::Key(key), - controls, - &mut self.remapping_keybindings, - ) { - for game_input in game_inputs { - match game_input { - GameInput::Fullscreen => { - if input.state == winit::event::ElementState::Pressed - && !Self::is_pressed( - &mut self.keypress_map, - GameInput::Fullscreen, - ) - { - self.toggle_fullscreen = !self.toggle_fullscreen; - } - Self::set_pressed( + let input_key = match input.virtual_keycode { + Some(key) => KeyMouse::Key(key), + None => KeyMouse::ScanKey(input.scancode), + }; + + if let Some(game_inputs) = + Window::map_input(input_key, controls, &mut self.remapping_keybindings) + { + for game_input in game_inputs { + match game_input { + GameInput::Fullscreen => { + if input.state == winit::event::ElementState::Pressed + && !Self::is_pressed( &mut self.keypress_map, GameInput::Fullscreen, - input.state, - ); - }, - GameInput::Screenshot => { - self.take_screenshot = input.state - == winit::event::ElementState::Pressed - && !Self::is_pressed( - &mut self.keypress_map, - GameInput::Screenshot, - ); - Self::set_pressed( + ) + { + self.toggle_fullscreen = !self.toggle_fullscreen; + } + Self::set_pressed( + &mut self.keypress_map, + GameInput::Fullscreen, + input.state, + ); + }, + GameInput::Screenshot => { + self.take_screenshot = input.state + == winit::event::ElementState::Pressed + && !Self::is_pressed( &mut self.keypress_map, GameInput::Screenshot, - input.state, ); - }, - _ => self.events.push(Event::InputUpdate( - *game_input, - input.state == winit::event::ElementState::Pressed, - )), - } + Self::set_pressed( + &mut self.keypress_map, + GameInput::Screenshot, + input.state, + ); + }, + _ => self.events.push(Event::InputUpdate( + *game_input, + input.state == winit::event::ElementState::Pressed, + )), } } }