From af892ad2081f7e38be5795539a0b6caa18fd1edd Mon Sep 17 00:00:00 2001 From: chixi4 Date: Sun, 1 Feb 2026 14:16:29 +0800 Subject: [PATCH] Fix duplicate key events on Windows On Windows, crossterm reports both KeyPress and KeyRelease events, causing each keystroke to be registered twice. Filter events to only handle KeyEventKind::Press to fix this issue. See: https://github.com/crossterm-rs/crossterm/issues/797 --- src/app/game.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/game.rs b/src/app/game.rs index 272325a..c59db16 100644 --- a/src/app/game.rs +++ b/src/app/game.rs @@ -1,4 +1,4 @@ -use crossterm::event::{self, Event, KeyCode}; +use crossterm::event::{self, Event, KeyCode, KeyEventKind}; use ratatui::backend::CrosstermBackend; use ratatui::Terminal; use std::io; @@ -32,7 +32,8 @@ impl Game { if crossterm::event::poll(timeout)? { if let Event::Key(key) = event::read()? { - if !self.handle_input(key.code) { + // Only handle key press events, ignore key release (fixes Windows double input bug) + if key.kind == KeyEventKind::Press && !self.handle_input(key.code) { return Ok(()); } }