From 7616f1e3f2c590ce294af0dc0f3c69d4df916791 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Thu, 16 Dec 2021 11:19:32 +0900 Subject: [PATCH] Fix key_press event not only on key down --- src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0b0c142..3cfb6c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ mod display; mod mpd_handler; use ggez::conf::{WindowMode, WindowSetup}; -use ggez::event::winit_event::{KeyboardInput, ModifiersState}; +use ggez::event::winit_event::{ElementState, KeyboardInput, ModifiersState}; use ggez::event::{self, ControlFlow, EventHandler}; use ggez::graphics::{self, Rect}; use ggez::{ContextBuilder, GameError}; @@ -79,6 +79,7 @@ fn main() -> Result<(), String> { input: KeyboardInput { virtual_keycode: Some(keycode), + state, .. }, is_synthetic: _, @@ -90,7 +91,9 @@ fn main() -> Result<(), String> { } _ => (), } - display.key_down_event(ctx, keycode, modifiers_state.into(), false); + if state == ElementState::Pressed { + display.key_down_event(ctx, keycode, modifiers_state.into(), false); + } } event::winit_event::WindowEvent::Resized(phys_size) => { graphics::set_screen_coordinates(