[GH-ISSUE #7707] Offhand key bound to a non-default key swaps the hovered item into hotbar slot 7 when a container is open (key translated twice) #3335

Open
opened 2026-11-03 04:07:37 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @oxi-does-dev on GitHub (Nov 2, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/7707

Originally assigned to: @oxi-does-dev on GitHub.

Bug description

A key bound key.swapOffhand to a non-default key (e.g. Left Alt) correctly swaps to the offhand while playing, but while any container screen (inventory/chest/…) is open, the hovered item is swapped into hotbar slot 7 instead — exactly as if the hotbar-7 key had been pressed.

In my case key.hotbar.7 is rebound to F and key.swapOffhand is Left Alt.

Steps to reproduce

  1. Options → Controls:
    • key.hotbar.7 = F
    • key.swapOffhand = Left Alt
  2. Hold any item in the main hand.
  3. Open the player inventory (or a chest), hover any slot.
  4. Press Left Alt (the swap-offhand key).

Expected (vanilla)

AbstractContainerScreen.checkHotbarKeyPressed receives the raw key press of the key bound to key.swapOffhand and swaps the hovered item with the offhand.

Actual

The hovered item is swapped with hotbar slot 7 (menu_click(slot, 6, Swap)), as if Digit7 had been pressed.
Outside of any container screen, Left Alt works correctly.

Root cause analysis — the key gets translated twice

  1. crates/horizon-client/src/game.rs — mapped_key_event() (~line 7521) translates the physical key into the default of the mapping bound to it via settings.keys.translate_all(key). So my physical Left Alt arrives to key_pressed() (~line 15813) as the already-translated KeyCode::KeyF (the vanilla default of key.swapOffhand).
  2. The container arm at ~line 15884 then calls settings.keys.container_hotbar_key(key) again (crates/horizon-client-input/src/keybinds.rs, container_hotbar_key, ~line 490), which resolves the code against the current bindings once more: the translated KeyF collides with my rebound key.hotbar.7 == key.keyboard.f, so it returns the hotbar mapping's default Digit7.
  3. inventory_hotkey(Digit7) swaps the hovered item with hotbar slot 7.
  4. In Screen::Playing the arm KeyCode::KeyF if self.screen == Screen::Playing (~line 15969) matches first, which is why the same key works fine outside containers.

So container_hotbar_key() documents "a rebound key swaps instead of reaching the screen" and has a passing test (container_hotkeys_follow_the_bound_keys) in raw keyspace — but the game-side caller feeds it an already-translated vanilla-default key code, effectively translating the key twice.

Fix ideas

  • Pass the raw physical key into the container arm (vanilla's Screen.keyPressed works in raw keyspace) and only there call container_hotbar_key, or
  • in mapped_key_event, remember which vanilla mapping produced the translated code and let the container arm reason about that mapping instead of re-resolving a key code that may itself be another mapping's bound key.

Environment

  • Linux x86-64 (Termux host), QWERTY keyboard
  • Horizon from the latest launcher nightly at the time of filing
  • Bindings: key.hotbar.7 = key.keyboard.f, key.swapOffhand = key.keyboard.left.alt
Originally created by @oxi-does-dev on GitHub (Nov 2, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/7707 Originally assigned to: @oxi-does-dev on GitHub. ## Bug description A key bound **`key.swapOffhand` to a non-default key** (e.g. Left Alt) correctly swaps to the offhand while playing, but **while any container screen (inventory/chest/…) is open, the hovered item is swapped into hotbar slot 7** instead — exactly as if the hotbar-7 key had been pressed. In my case `key.hotbar.7` is rebound to **F** and `key.swapOffhand` is **Left Alt**. ### Steps to reproduce 1. Options → Controls: - `key.hotbar.7` = **F** - `key.swapOffhand` = **Left Alt** 2. Hold any item in the main hand. 3. Open the player inventory (or a chest), hover any slot. 4. Press **Left Alt** (the swap-offhand key). ### Expected (vanilla) `AbstractContainerScreen.checkHotbarKeyPressed` receives the **raw** key press of the key bound to `key.swapOffhand` and swaps the hovered item with the offhand. ### Actual The hovered item is swapped with **hotbar slot 7** (`menu_click(slot, 6, Swap)`), as if `Digit7` had been pressed. Outside of any container screen, Left Alt works correctly. ### Root cause analysis — the key gets translated twice 1. `crates/horizon-client/src/game.rs` — `mapped_key_event()` (~line 7521) translates the **physical** key into the *default* of the mapping bound to it via `settings.keys.translate_all(key)`. So my physical **Left Alt** arrives to `key_pressed()` (~line 15813) as the already-translated `KeyCode::KeyF` (the vanilla default of `key.swapOffhand`). 2. The container arm at ~line 15884 then calls `settings.keys.container_hotbar_key(key)` again (`crates/horizon-client-input/src/keybinds.rs`, `container_hotbar_key`, ~line 490), which resolves the code against the **current bindings** once more: the translated `KeyF` collides with my rebound `key.hotbar.7 == key.keyboard.f`, so it returns the hotbar mapping's default `Digit7`. 3. `inventory_hotkey(Digit7)` swaps the hovered item with hotbar slot 7. 4. In `Screen::Playing` the arm `KeyCode::KeyF if self.screen == Screen::Playing` (~line 15969) matches first, which is why the same key works fine outside containers. So `container_hotbar_key()` documents *"a rebound key swaps instead of reaching the screen"* and has a passing test (`container_hotkeys_follow_the_bound_keys`) in raw keyspace — but the game-side caller feeds it an already-translated vanilla-default key code, effectively translating the key **twice**. ### Fix ideas - Pass the **raw physical** key into the container arm (vanilla's `Screen.keyPressed` works in raw keyspace) and only there call `container_hotbar_key`, or - in `mapped_key_event`, remember which vanilla mapping produced the translated code and let the container arm reason about that mapping instead of re-resolving a key code that may itself be another mapping's bound key. ### Environment - Linux x86-64 (Termux host), QWERTY keyboard - Horizon from the latest launcher nightly at the time of filing - Bindings: `key.hotbar.7 = key.keyboard.f`, `key.swapOffhand = key.keyboard.left.alt`
Author
Owner

@oxi-does-dev commented on GitHub (Nov 2, 2026):

/claim

<!-- gh-comment-id:6587057375 --> @oxi-does-dev commented on GitHub (Nov 2, 2026): /claim
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#3335
No description provided.