diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 2f12e5136..0c5b0fdba 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -4720,6 +4720,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}; @@ -7962,7 +7968,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 e3625d9b0..f604ca7d8 100644 --- a/crates/horizon-client/src/game/control.rs +++ b/crates/horizon-client/src/game/control.rs @@ -653,7 +653,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, @@ -674,6 +681,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, @@ -705,7 +713,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;