From 293c589e35b5af7389c2110a2c6b3db5a92ece8a Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 15 Oct 2026 16:50:44 +0200 Subject: [PATCH] Read the physical Shift and Ctrl keys on every container screen The workstation screens (anvil, grindstone, stonecutter, smithing, enchanting, cartography, loom, beacon, villager trading, brewing stand), the horse/llama/camel inventory and the creative item grid read Shift from the sneak mapping (`keys`). Behind a screen a Shift press never reaches the mapping (KeyboardHandler.keyPress: only releases do) and Right Shift isn't mapped at all, so shift-click there worked only when Shift was already held before the screen opened. They now read `has_shift_down` like AbstractContainerScreen (`InputWithModifiers.hasShiftDown`), and the recipe book reads Ctrl the same way (`Minecraft.hasControlDown`). `status` reports `physical_keys` so scripts can check what the OS delivered. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game.rs | 8 +++++++- crates/horizon-client/src/game/control.rs | 14 ++++++++++++-- crates/horizon-client/src/game/mount_menu.rs | 3 +-- crates/horizon-client/src/game/recipe_book.rs | 7 +++---- crates/horizon-client/src/game/stations.rs | 3 +-- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 16fa59240..74984fa5f 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -4714,6 +4714,12 @@ impl Game<'_> { self.physical_keys.contains(&KeyCode::ShiftLeft) || self.physical_keys.contains(&KeyCode::ShiftRight) } + /// `Minecraft.hasControlDown`: the physical Control keys, whatever the + /// sprint key is bound or toggled to. + pub(super) fn has_control_down(&self) -> bool { + self.physical_keys.contains(&KeyCode::ControlLeft) + || self.physical_keys.contains(&KeyCode::ControlRight) + } /// `hasClickedOutside` of the open screen at the cursor. fn clicked_outside(&self, batch: &HudBatch) -> bool { use horizon_client::container_screen::{Book, Image, clicked_outside}; @@ -7956,7 +7962,7 @@ impl Game<'_> { { return; } - let shift = self.keys.contains(&KeyCode::ShiftLeft); + let shift = self.has_shift_down(); let items = self.creative_screen.items(&self.res.names); let first = self.creative_screen.first_row(&self.res.names); for r in 0..5 { diff --git a/crates/horizon-client/src/game/control.rs b/crates/horizon-client/src/game/control.rs index af981b798..48c0ab21a 100644 --- a/crates/horizon-client/src/game/control.rs +++ b/crates/horizon-client/src/game/control.rs @@ -629,7 +629,14 @@ impl Game<'_> { "gpu_reserved_bytes": memory.as_ref().map(|m| m.total_reserved_bytes), }) }); - json!({ + // The keyboard as the OS reports it (screens read Shift and Ctrl here). + let mut physical_keys: Vec<_> = self + .physical_keys + .iter() + .map(|k| format!("{k:?}")) + .collect(); + physical_keys.sort(); + let mut status = json!({ "screen": self.screen_name(), "debug": { "overlay": self.debug, @@ -650,6 +657,7 @@ impl Game<'_> { "held": self.held().map(|s| json!({ "item": &*s.item, "count": s.count })), "offhand": self.offhand.as_ref().map(|s| json!({ "item": &*s.item, "count": s.count, "damage": s.damage })), "keys": self.keys.iter().map(|k| format!("{k:?}")).collect::>(), + // The keyboard as the OS reports it (Shift and Ctrl in screens). "fps": self.fps, "frames": self.frames, "ticks": self.ticks, @@ -681,7 +689,9 @@ impl Game<'_> { })), "uptime_seconds": self.started.elapsed().as_secs_f64(), "server": self.remote_status(), - }) + }); + status["physical_keys"] = json!(physical_keys); + status } } diff --git a/crates/horizon-client/src/game/mount_menu.rs b/crates/horizon-client/src/game/mount_menu.rs index 8fe819a96..8f70f6754 100644 --- a/crates/horizon-client/src/game/mount_menu.rs +++ b/crates/horizon-client/src/game/mount_menu.rs @@ -224,8 +224,7 @@ impl Game<'_> { let Some(slot) = self.slot_at(&batch, self.cursor.0, self.cursor.1) else { return true; }; - let shift = self.keys.contains(&winit::keyboard::KeyCode::ShiftLeft) - || self.keys.contains(&winit::keyboard::KeyCode::ShiftRight); + let shift = self.has_shift_down(); if shift { self.mount_quick_move(slot); } else if slot >= SADDLE { diff --git a/crates/horizon-client/src/game/recipe_book.rs b/crates/horizon-client/src/game/recipe_book.rs index ef4caa988..01e637a50 100644 --- a/crates/horizon-client/src/game/recipe_book.rs +++ b/crates/horizon-client/src/game/recipe_book.rs @@ -173,12 +173,12 @@ impl Game<'_> { } /// A key press while the search box has focus. pub(super) fn recipe_key(&mut self, event: &winit::event::KeyEvent) { - use winit::keyboard::{KeyCode, PhysicalKey}; + use winit::keyboard::PhysicalKey; if let Some(shortcut) = self.edit_shortcut(event) { self.recipe_shortcut(shortcut); return; } - let ctrl = self.keys.contains(&KeyCode::ControlLeft); + let ctrl = self.has_control_down(); let shift = self.has_shift_down(); let Some(search) = self.recipe_ui.search.as_mut() else { return; @@ -888,8 +888,7 @@ impl Game<'_> { self.draw_book_panel(batch, book_type); } fn shift_down_or_ctrl(&self) -> bool { - use winit::keyboard::KeyCode; - self.keys.contains(&KeyCode::ControlLeft) || self.keys.contains(&KeyCode::ControlRight) + self.has_control_down() } /// `GhostSlots.extractRenderState`, among the container's slots. fn draw_ghost(&mut self, batch: &mut HudBatch, book_type: BookType) { diff --git a/crates/horizon-client/src/game/stations.rs b/crates/horizon-client/src/game/stations.rs index 5642a24c7..bb8e448b2 100644 --- a/crates/horizon-client/src/game/stations.rs +++ b/crates/horizon-client/src/game/stations.rs @@ -1061,8 +1061,7 @@ impl Game<'_> { let batch = HudBatch::new(size); let (ox, oy) = self.inventory_origin(&batch); let local = (self.cursor.0 - ox, self.cursor.1 - oy); - let shift = self.keys.contains(&winit::keyboard::KeyCode::ShiftLeft) - || self.keys.contains(&winit::keyboard::KeyCode::ShiftRight); + let shift = self.has_shift_down(); if let Some(kind) = self.station.as_ref().map(|s| s.kind) { if kind == Kind::Merchant && !right && self.merchant_click(local) { return true;