Make modifiers sticky
Also removes the use of the deprecated modifiers field in
event::KeyboardInput
use super::super::super::{Console, GameState, Rltk};
use super::super::*;
use glow::HasContext;
-use glutin::{event::Event, event::WindowEvent, event_loop::ControlFlow};
+use glutin::{event::DeviceEvent, event::Event, event::WindowEvent, event_loop::ControlFlow};
use std::time::Instant;
const TICK_TYPE: ControlFlow = ControlFlow::Poll;
@@ -39,9 +39,6 @@ pub fn main_loop<GS: GameState>(mut rltk: Rltk, mut gamestate: GS) {
Event::NewEvents(_) => {
rltk.left_click = false;
rltk.key = None;
- rltk.shift = false;
- rltk.control = false;
- rltk.alt = false;
}
Event::MainEventsCleared => {
tock(
@@ -54,6 +51,14 @@ pub fn main_loop<GS: GameState>(mut rltk: Rltk, mut gamestate: GS) {
);
wc.swap_buffers().unwrap();
}
+ Event::DeviceEvent {
+ event: DeviceEvent::ModifiersChanged(modifiers),
+ ..
+ } => {
+ rltk.shift = modifiers.shift();
+ rltk.alt = modifiers.alt();
+ rltk.control = modifiers.ctrl();
+ }
Event::LoopDestroyed => (),
Event::WindowEvent { ref event, .. } => match event {
WindowEvent::Resized(physical_size) => {
@@ -94,21 +99,11 @@ pub fn main_loop<GS: GameState>(mut rltk: Rltk, mut gamestate: GS) {
glutin::event::KeyboardInput {
virtual_keycode: Some(virtual_keycode),
state: glutin::event::ElementState::Pressed,
- modifiers,
..
},
..
} => {
rltk.key = Some(*virtual_keycode);
- if modifiers.shift() {
- rltk.shift = true;
- }
- if modifiers.alt() {
- rltk.alt = true;
- }
- if modifiers.ctrl() {
- rltk.control = true;
- }
}
_ => (),
