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 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-15 16:50:44 +02:00
parent 58af88f809
commit 293c589e35
5 changed files with 24 additions and 11 deletions
+7 -1
View File
@@ -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 {
+12 -2
View File
@@ -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::<Vec<_>>(),
// 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
}
}
+1 -2
View File
@@ -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 {
@@ -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) {
+1 -2
View File
@@ -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;