Fix key_press event not only on key down

This commit is contained in:
Stephen Seo 2021-12-16 11:19:32 +09:00
parent 7fb3525ec7
commit 7616f1e3f2

View file

@ -3,7 +3,7 @@ mod display;
mod mpd_handler; mod mpd_handler;
use ggez::conf::{WindowMode, WindowSetup}; 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::event::{self, ControlFlow, EventHandler};
use ggez::graphics::{self, Rect}; use ggez::graphics::{self, Rect};
use ggez::{ContextBuilder, GameError}; use ggez::{ContextBuilder, GameError};
@ -79,6 +79,7 @@ fn main() -> Result<(), String> {
input: input:
KeyboardInput { KeyboardInput {
virtual_keycode: Some(keycode), virtual_keycode: Some(keycode),
state,
.. ..
}, },
is_synthetic: _, 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) => { event::winit_event::WindowEvent::Resized(phys_size) => {
graphics::set_screen_coordinates( graphics::set_screen_coordinates(