[PR #3561] [MERGED] Repeat attack and use clicks while a key bound to them is held #5052

Closed
opened 2026-11-03 05:09:53 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/3561
Author: @d3grando
Created: 10/29/2026
Status: ✅ Merged
Merged: 10/29/2026
Merged by: @ludovic111

Base: main ← Head: fix-3243


📝 Commits (1)

  • e214657 Repeat attack and use clicks while a key bound to them is held

📊 Changes

2 files changed (+31 additions, -3 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+29 -2)
📝 crates/horizon-client/src/game/control.rs (+2 -1)

📄 Description

🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves.

What and why

Fixes #3243

With a keyboard key bound to Attack/Destroy (the reporter uses Space), holding the key attacked once. In vanilla it keeps attacking while it is held, as the OS repeats the key.

Key binds that map a keyboard key to a mouse mapping (key.attack, key.use, key.pickItem) are dispatched to play_mouse from the window's KeyboardInput handler, and that branch skipped every event with event.repeat set. So only the first press clicked. In vanilla KeyboardHandler.keyPress treats a repeat like a press here: with no screen open it calls KeyMapping.set(key, true) and KeyMapping.click(key) for any action other than release, and Minecraft.handleKeybinds turns each click into startAttack (or startUseItem, pickBlock).

The branch now goes through a small keyboard_button(playing, action) helper: in game, a press and a repeat both press the button, and a release releases it; behind a screen nothing happens, as before. Repeats go through the same play_mouse path as the press, so the toggle options behave as vanilla's ToggleKeyMapping.setDown(true) does on a repeat.

horizon-ctl key KEY repeat released a mouse-mapped key right after pressing it, unlike the window's repeat; it now keeps it held (up and tap still release).

Vanilla reference

net.minecraft.client.KeyboardHandler.keyPress (javap of the 26.3 client jar): if (action == 0) { KeyMapping.set(key, false); return; } and later, with no screen, KeyMapping.set(key, true); KeyMapping.click(key); for both PRESS (1) and REPEAT (2). ToggleKeyMapping.setDown flips a toggled mapping on every set(true). Mouse buttons have no repeats (MouseHandler.onButton), so holding the left mouse button still attacks once and then keeps mining, as before.

No harness covers input dispatch. The new bin test game::tests::a_held_key_bound_to_a_button_repeats_its_clicks checks the helper.

Before (the helper with main's rule, which skips repeats):

test game::tests::a_held_key_bound_to_a_button_repeats_its_clicks ... FAILED
assertion `left == right` failed
  left: None
 right: Some(true)
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 145 filtered out

After:

test game::tests::a_held_key_bound_to_a_button_repeats_its_clicks ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 145 filtered out

Self-check

Run on Windows 11. tools/pr_ready.py was not run; these are the commands I ran:

cargo fmt --all -- --check                                                    ok
cargo clippy -p horizon-client --features mods --all-targets -- -D warnings   ok
cargo test -p horizon-client --features mods --bin horizon-client a_held_key  1 passed (fails with main's rule)
cargo build --profile fast -p horizon-client --features mods --bins           ok

In game

In game (single player, creative): key_key.attack:key.keyboard.space, key_key.jump:key.keyboard.j, facing a NoAI zombie with 1000 health and knockback resistance 1 at 2 blocks. The held key is real window input: a WM_KEYDOWN, then WM_KEYDOWNs with lParam bit 30 set (the OS's auto-repeat, which winit reports as repeat), then WM_KEYUP, posted to the game window.

Held Space origin/main this branch
10 repeats, 600 ms apart 1000 → 999.06 (one hit) 1000 → 989.66 (11 hits)
60 repeats, 33 ms apart (typical OS rate) 1000 → 999.06 (one hit) 1000 → 997.68 (several hits; the 10-tick hurt cooldown and the reset attack strength limit the damage, as in vanilla)

After the key is released the health stays put (no stuck attack).

The health values above are /data get entity ... Health readouts of the zombie, taken in game on origin/main and on this branch with the same input script.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/3561 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/29/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix-3243` --- ### 📝 Commits (1) - [`e214657`](https://github.com/horizon-rust/horizon/commit/e2146572a6aaa50255967b25e3ebf3635d73248e) Repeat attack and use clicks while a key bound to them is held ### 📊 Changes **2 files changed** (+31 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+29 -2) 📝 `crates/horizon-client/src/game/control.rs` (+2 -1) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves. ## What and why Fixes #3243 With a keyboard key bound to Attack/Destroy (the reporter uses Space), holding the key attacked once. In vanilla it keeps attacking while it is held, as the OS repeats the key. Key binds that map a keyboard key to a mouse mapping (`key.attack`, `key.use`, `key.pickItem`) are dispatched to `play_mouse` from the window's `KeyboardInput` handler, and that branch skipped every event with `event.repeat` set. So only the first press clicked. In vanilla `KeyboardHandler.keyPress` treats a repeat like a press here: with no screen open it calls `KeyMapping.set(key, true)` and `KeyMapping.click(key)` for any action other than release, and `Minecraft.handleKeybinds` turns each click into `startAttack` (or `startUseItem`, `pickBlock`). The branch now goes through a small `keyboard_button(playing, action)` helper: in game, a press and a repeat both press the button, and a release releases it; behind a screen nothing happens, as before. Repeats go through the same `play_mouse` path as the press, so the toggle options behave as vanilla's `ToggleKeyMapping.setDown(true)` does on a repeat. `horizon-ctl key KEY repeat` released a mouse-mapped key right after pressing it, unlike the window's repeat; it now keeps it held (`up` and `tap` still release). ## Vanilla reference `net.minecraft.client.KeyboardHandler.keyPress` (javap of the 26.3 client jar): `if (action == 0) { KeyMapping.set(key, false); return; }` and later, with no screen, `KeyMapping.set(key, true); KeyMapping.click(key);` for both `PRESS` (1) and `REPEAT` (2). `ToggleKeyMapping.setDown` flips a toggled mapping on every `set(true)`. Mouse buttons have no repeats (`MouseHandler.onButton`), so holding the left mouse button still attacks once and then keeps mining, as before. No harness covers input dispatch. The new bin test `game::tests::a_held_key_bound_to_a_button_repeats_its_clicks` checks the helper. Before (the helper with main's rule, which skips repeats): ``` test game::tests::a_held_key_bound_to_a_button_repeats_its_clicks ... FAILED assertion `left == right` failed left: None right: Some(true) test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 145 filtered out ``` After: ``` test game::tests::a_held_key_bound_to_a_button_repeats_its_clicks ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 145 filtered out ``` ## Self-check Run on Windows 11. `tools/pr_ready.py` was not run; these are the commands I ran: ``` cargo fmt --all -- --check ok cargo clippy -p horizon-client --features mods --all-targets -- -D warnings ok cargo test -p horizon-client --features mods --bin horizon-client a_held_key 1 passed (fails with main's rule) cargo build --profile fast -p horizon-client --features mods --bins ok ``` ## In game In game (single player, creative): `key_key.attack:key.keyboard.space`, `key_key.jump:key.keyboard.j`, facing a NoAI zombie with 1000 health and knockback resistance 1 at 2 blocks. The held key is real window input: a `WM_KEYDOWN`, then `WM_KEYDOWN`s with lParam bit 30 set (the OS's auto-repeat, which winit reports as `repeat`), then `WM_KEYUP`, posted to the game window. | Held Space | origin/main | this branch | |---|---|---| | 10 repeats, 600 ms apart | 1000 → 999.06 (one hit) | 1000 → 989.66 (11 hits) | | 60 repeats, 33 ms apart (typical OS rate) | 1000 → 999.06 (one hit) | 1000 → 997.68 (several hits; the 10-tick hurt cooldown and the reset attack strength limit the damage, as in vanilla) | After the key is released the health stays put (no stuck attack). The health values above are `/data get entity ... Health` readouts of the zombie, taken in game on origin/main and on this branch with the same input script. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:09:53 +07:00
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#5052
No description provided.