[GH-ISSUE #4974] [Bug] A key or mouse button held when a server dialog opens stays down: the player keeps walking and use-clicking until it is pressed again #1505

Closed
opened 2026-11-02 15:47:31 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @Perdume on GitHub (Oct 31, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/4974

Originally assigned to: @doodlyyousuf on GitHub.

What happens

When a dialog opens (ClientboundShowDialog, a show_dialog click event or /dialog show) while a key or the use button is held, the
release that follows is lost, and the game goes on as if the key or button were still down after the dialog closes:

  1. Walking forward (W held) as a dialog opens: after the dialog is closed the player keeps walking forward until W is pressed and
    released again.
  2. The use button held as the dialog opens (for example the right-click that triggered it): the game keeps right-clicking (item use
    repeats every 4 ticks) until the player clicks again. By the code below it also does so while the dialog is still open.

Vanilla releases every held key when a screen opens, so neither happens there.

Where it comes from

Checked on main at 4de90a1. The same code is in nightly-2026-10-30-ba6344a (the version I ran), at other line numbers.

  • crates/horizon-client/src/game.rs, window_event: KeyboardInput ... if self.dialog_open() (line 15030) acts on Pressed only
    (dialog_key). A key release is dropped, so a key that was in self.keys when the dialog opened is never removed.
  • MouseInput ... if self.dialog_open() (line 14781) handles the left button only. A release of the right (or middle) button is
    dropped, so self.right is never cleared.
  • track_toggle_screens (line 6657) is documented as "KeyMapping.releaseAll when a screen opens and
    restoreToggleStatesOnScreenClosed when it closes", but it decides with self.screen == Screen::Playing && self.title.is_none().
    A dialog does not change self.screen (it is self.dialogs.open), so the function never sees a screen opening: the toggle keys
    are not released and keys, left and right are not touched.
  • show_dialog (game/dialogs.rs:117) ends with self.capture(false) (line 202), which stops mining and resets the inventory
    clicks, and nothing else about input.
  • The other overlays reset the input themselves when they open: chat sets keys.clear(), left = false, right = false
    (game/chat.rs:571-573), the server pack prompt clears keys (game/server_packs.rs:281). The dialog is the one that does not.
  • Why the use button repeats: the port of Minecraft.handleKeybinds (game.rs:6598) repeats a held use while
    self.right && self.use_delay == 0 && self.using.is_none() && self.screen == Screen::Playing. self.screen is still Playing
    behind a dialog, so a stale self.right keeps firing, during the dialog as well.

Vanilla reference

Horizon's own comment on track_toggle_screens says vanilla calls KeyMapping.releaseAll() when a screen opens, and a dialog is a
screen there (DialogScreen). I have not checked that against the pinned bytecode with tools/rea_vanilla.py; whoever fixes this
may want to.

Suggested direction

Count an open dialog as a screen in track_toggle_screens, and drop what is held while one is open:

fn track_toggle_screens(&mut self) {
    let dialog = self.dialog_open();
    if dialog {
        // The dialog drops key releases and every mouse button but the left.
        self.keys.clear();
        self.left = false;
        self.right = false;
    }
    let playing = self.screen == Screen::Playing && self.title.is_none() && !dialog;
    // ... unchanged; when a screen opens because of a dialog, also self.physical_keys.clear()
}

This releases toggled sneak, sprint and attack when the dialog opens and restores them when it closes, like for any other screen,
and it also covers a dialog that opens while chat is still up (the chat screen has been tracking keys). Clearing keys, left and
right in show_dialog, as chat does, would be smaller but would leave the toggles held and would miss that case.

Tested

I tried the change above as a native mod (a HEAD hook on track_toggle_screens, built on nightly-2026-10-30-ba6344a). The scenario
that showed the bug before (walking forward and opening a dialog, then the repeating right-click) no longer does: the player does
not keep walking or use-clicking after the dialog opens. A stand-in model of the toggle keys, written from reading the code, gives
the same result (the original keeps both held, the change does not, toggled sneak is restored, and without a dialog the two
behave the same).

A regression test could hold W and the use button, open a dialog, release both behind it, close it, and assert that nothing is
held and the player does not move.

Environment

  • Horizon: nightly-2026-10-30-ba6344a (launcher 0.2.0)
  • OS: Windows 11 Pro 10.0.26200, keyboard and mouse
  • #1734 and #1735 added the server dialog screen and its inputs; #3205 and #4554 are about /dialog show and data pack dialogs.
  • No open or closed issue found for "dialog stuck key", "held key dialog", "keeps walking", "releaseAll", "dialog use button" or
    "right click dialog".

Suggested label: bug.

Originally created by @Perdume on GitHub (Oct 31, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/4974 Originally assigned to: @doodlyyousuf on GitHub. ## What happens When a dialog opens (`ClientboundShowDialog`, a `show_dialog` click event or `/dialog show`) while a key or the use button is held, the release that follows is lost, and the game goes on as if the key or button were still down after the dialog closes: 1. Walking forward (W held) as a dialog opens: after the dialog is closed the player keeps walking forward until W is pressed and released again. 2. The use button held as the dialog opens (for example the right-click that triggered it): the game keeps right-clicking (item use repeats every 4 ticks) until the player clicks again. By the code below it also does so while the dialog is still open. Vanilla releases every held key when a screen opens, so neither happens there. ## Where it comes from Checked on main at 4de90a1. The same code is in nightly-2026-10-30-ba6344a (the version I ran), at other line numbers. - `crates/horizon-client/src/game.rs`, `window_event`: `KeyboardInput ... if self.dialog_open()` (line 15030) acts on `Pressed` only (`dialog_key`). A key release is dropped, so a key that was in `self.keys` when the dialog opened is never removed. - `MouseInput ... if self.dialog_open()` (line 14781) handles the left button only. A release of the right (or middle) button is dropped, so `self.right` is never cleared. - `track_toggle_screens` (line 6657) is documented as "`KeyMapping.releaseAll` when a screen opens and `restoreToggleStatesOnScreenClosed` when it closes", but it decides with `self.screen == Screen::Playing && self.title.is_none()`. A dialog does not change `self.screen` (it is `self.dialogs.open`), so the function never sees a screen opening: the toggle keys are not released and `keys`, `left` and `right` are not touched. - `show_dialog` (`game/dialogs.rs:117`) ends with `self.capture(false)` (line 202), which stops mining and resets the inventory clicks, and nothing else about input. - The other overlays reset the input themselves when they open: chat sets `keys.clear()`, `left = false`, `right = false` (`game/chat.rs:571-573`), the server pack prompt clears `keys` (`game/server_packs.rs:281`). The dialog is the one that does not. - Why the use button repeats: the port of `Minecraft.handleKeybinds` (`game.rs:6598`) repeats a held use while `self.right && self.use_delay == 0 && self.using.is_none() && self.screen == Screen::Playing`. `self.screen` is still `Playing` behind a dialog, so a stale `self.right` keeps firing, during the dialog as well. ## Vanilla reference Horizon's own comment on `track_toggle_screens` says vanilla calls `KeyMapping.releaseAll()` when a screen opens, and a dialog is a screen there (`DialogScreen`). I have not checked that against the pinned bytecode with `tools/rea_vanilla.py`; whoever fixes this may want to. ## Suggested direction Count an open dialog as a screen in `track_toggle_screens`, and drop what is held while one is open: ```rust fn track_toggle_screens(&mut self) { let dialog = self.dialog_open(); if dialog { // The dialog drops key releases and every mouse button but the left. self.keys.clear(); self.left = false; self.right = false; } let playing = self.screen == Screen::Playing && self.title.is_none() && !dialog; // ... unchanged; when a screen opens because of a dialog, also self.physical_keys.clear() } ``` This releases toggled sneak, sprint and attack when the dialog opens and restores them when it closes, like for any other screen, and it also covers a dialog that opens while chat is still up (the chat screen has been tracking keys). Clearing `keys`, `left` and `right` in `show_dialog`, as chat does, would be smaller but would leave the toggles held and would miss that case. ## Tested I tried the change above as a native mod (a HEAD hook on `track_toggle_screens`, built on nightly-2026-10-30-ba6344a). The scenario that showed the bug before (walking forward and opening a dialog, then the repeating right-click) no longer does: the player does not keep walking or use-clicking after the dialog opens. A stand-in model of the toggle keys, written from reading the code, gives the same result (the original keeps both held, the change does not, toggled sneak is restored, and without a dialog the two behave the same). A regression test could hold W and the use button, open a dialog, release both behind it, close it, and assert that nothing is held and the player does not move. ## Environment - Horizon: nightly-2026-10-30-ba6344a (launcher 0.2.0) - OS: Windows 11 Pro 10.0.26200, keyboard and mouse ## Related - #1734 and #1735 added the server dialog screen and its inputs; #3205 and #4554 are about `/dialog show` and data pack dialogs. - No open or closed issue found for "dialog stuck key", "held key dialog", "keeps walking", "releaseAll", "dialog use button" or "right click dialog". Suggested label: `bug`.
Author
Owner

@doodlyyousuf commented on GitHub (Oct 31, 2026):

🤖 Agent: /claim

<!-- gh-comment-id:6539724239 --> @doodlyyousuf commented on GitHub (Oct 31, 2026): 🤖 Agent: /claim
Author
Owner

@doodlyyousuf commented on GitHub (Oct 31, 2026):

🤖 Agent: Opened https://github.com/horizon-rust/horizon/pull/5002

<!-- gh-comment-id:6540006688 --> @doodlyyousuf commented on GitHub (Oct 31, 2026): 🤖 Agent: Opened https://github.com/horizon-rust/horizon/pull/5002
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#1505
No description provided.