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
This commit is contained in:
Adam Blanchet 2020-12-16 10:40:08 +01:00
parent 55c49f88e6
commit 5f9984df12
2 changed files with 40 additions and 36 deletions

View File

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Reflective LoD water - Reflective LoD water
- Map indicators for group members - Map indicators for group members
- Hot-reloading for i18n, sounds, loot lotteries, and more - Hot-reloading for i18n, sounds, loot lotteries, and more
- Initial support for alternate style keyboards
### Changed ### Changed

View File

@ -311,6 +311,7 @@ pub type EventLoop = winit::event_loop::EventLoop<()>;
pub enum KeyMouse { pub enum KeyMouse {
Key(winit::event::VirtualKeyCode), Key(winit::event::VirtualKeyCode),
Mouse(winit::event::MouseButton), Mouse(winit::event::MouseButton),
ScanKey(winit::event::ScanCode),
} }
impl fmt::Display for KeyMouse { impl fmt::Display for KeyMouse {
@ -487,6 +488,7 @@ impl fmt::Display for KeyMouse {
Mouse(MouseButton::Other(button)) => Mouse(MouseButton::Other(button)) =>
// Additional mouse buttons after middle click start at 1 // Additional mouse buttons after middle click start at 1
return write!(f, "M{}", button + 3), return write!(f, "M{}", button + 3),
ScanKey(_) => "Unknown",
}) })
} }
} }
@ -992,12 +994,14 @@ impl Window {
return; return;
} }
if let Some(key) = input.virtual_keycode { let input_key = match input.virtual_keycode {
if let Some(game_inputs) = Window::map_input( Some(key) => KeyMouse::Key(key),
KeyMouse::Key(key), None => KeyMouse::ScanKey(input.scancode),
controls, };
&mut self.remapping_keybindings,
) { if let Some(game_inputs) =
Window::map_input(input_key, controls, &mut self.remapping_keybindings)
{
for game_input in game_inputs { for game_input in game_inputs {
match game_input { match game_input {
GameInput::Fullscreen => { GameInput::Fullscreen => {
@ -1035,7 +1039,6 @@ impl Window {
} }
} }
} }
}
}, },
WindowEvent::Focused(state) => { WindowEvent::Focused(state) => {
self.focused = state; self.focused = state;