[PR #5617] [MERGED] Native mods: screen_key_pressed and screen_char_typed, keys over the open screen (API next) #6390

Closed
opened 2026-11-03 06:19:49 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5617
Author: @Sylviromi
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @levzzz5154

Base: main ← Head: screen-key-input


📝 Commits (9)

  • 7a6468b Native mods: the screen hears of a key and of each typed character first
  • dd72fb8 Merge branch 'screen-mouse-scrolled' into screen-key-input
  • adb8f73 Native mods: a cancelled key still types the characters left, and the socket's backspace stays a key
  • 9d255bb Merge branch 'screen-mouse-scrolled' into screen-key-input
  • f750400 Native mods: a key's characters reach the screen after the key has acted
  • 885a33e Native mods: the world options boxes type a key's characters only
  • bbc31dd Merge remote-tracking branch 'hr/main' into pr-5617
  • 8560cb7 Creative search: a number key the hovered slot took types nothing; scroll hook doc: discrete scrolling, scroll-at
  • 2f077e8 Merge remote-tracking branch 'hr/main' into pr-5617

📊 Changes

7 files changed (+410 additions, -56 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+67 -1)
📝 crates/horizon-client/src/game/control.rs (+88 -42)
📝 crates/horizon-client/src/game/ime.rs (+7 -0)
📝 crates/horizon-client/src/game/lan_screen.rs (+15 -4)
📝 crates/horizon-client/src/game/native_hooks.rs (+223 -8)
➕ tools/native-hook-fragments/screen_key_input.json (+9 -0)
📝 tools/native-hook-fragments/screen_mouse_scrolled.json (+1 -1)

📄 Description

🤖 Opened by Sylviromi's AI agent (Claude Code, claude-sonnet-5-5), not by Sylviromi personally.

Part of #5543 (keys and typed characters; with this the set of six screen hooks is complete). Stacked on #5616, which is stacked on #5578: the commits up to the merge of #5616's branch are theirs; this PR's own commit is 7a6468bd8 (plus the merge dd72fb827 that brings #5616 forward). Review 7a6468bd8 only; after #5616 merges this diff is ~215 lines.

What and why

Adds native_screen_key_pressed_pre and native_screen_char_typed_pre (NeoForge ScreenEvent.KeyPressed.Pre / CharacterTyped.Pre), so a native mod can take a key or a typed character on an open screen before the game does. Hook API: next.

  • native_screen_key_pressed_pre(&self, screen: &NativeScreenView, key: &str, repeat: bool, modifiers: u32, canceled: &mut bool). key is vanilla's key name (key.keyboard.e, the name native_key hands over; a key with no name fires nothing). repeat marks the keyboard's auto-repeat (Horizon's extra; NeoForge folds repeats into the event).
  • native_screen_char_typed_pre(&self, screen: &NativeScreenView, c: char, modifiers: u32, canceled: &mut bool).
  • A cancelled press goes no further: no focus move, no Escape-close, no inventory or hotbar key, no text box, no native_key. Its release still arrives, so a native_key listener sees a release without its press.
  • A cancelled character drops only that character and never reaches a text box. Characters fire even when the press was cancelled, as vanilla delivers charTyped anyway; control characters (Enter, Backspace, Tab, Delete, Escape, a Control letter) are keys and fire nothing.
  • Fired from the window's key event (after the fullscreen, screenshot, debug and narrator keys), and also from the control socket's key and type commands and the input method's committed text, so the same hooks cover every way text reaches a screen.
  • Same gate as the mouse hooks: Options and the pack list opened from the title screen fire; the title screen itself, connect/loading screens, prompts/books/sign editors over gameplay and a world loading or saving never do.
  • Pending fragment: tools/native-hook-fragments/screen_key_input.json.

In-game proof

A test native mod cancelled keys on the open screen, built into the game and run offscreen: pressing E on the open inventory was cancelled and the inventory stayed open, while Escape went through and closed it. Typing "axb" in chat with 'x' cancelled left "ab". No screenshot: the hook has no visuals of its own.

Kind

  • feature: something new for players (listed under New in the release notes)

Label: feature

Vanilla reference

NeoForge ScreenEvent.KeyPressed.Pre / CharacterTyped.Pre, fired from KeyboardHandler.keyPress / charTyped before Screen.keyPressed / charTyped. There is no parity harness for this ticket (it adds hooks, no vanilla behaviour changes).

Other projects' code

none

Self-check

Note: the pr_ready run below covers this PR and #5616 together, against screen-mouse-button; the scope counts both.

pr_ready (tools/pr_ready.py --quick)

Check Result
Scope ✅ 6 files, +275 −4
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 510 passed
rustfmt ✅
clippy ✅
tests: horizon-client ✅ 1580 passed
doc tests ✅
launcher ➖ launcher untouched
Parity ➖ not run locally: CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

"Allow edits by maintainers" is on (default for fork PRs).

🤖 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/5617 **Author:** [@Sylviromi](https://github.com/Sylviromi) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `screen-key-input` --- ### 📝 Commits (9) - [`7a6468b`](https://github.com/horizon-rust/horizon/commit/7a6468bd8fee22004625cf770304e812806c7356) Native mods: the screen hears of a key and of each typed character first - [`dd72fb8`](https://github.com/horizon-rust/horizon/commit/dd72fb827751e138f09c357e4f8c0448b4d8cb71) Merge branch 'screen-mouse-scrolled' into screen-key-input - [`adb8f73`](https://github.com/horizon-rust/horizon/commit/adb8f735ec6c1787667f01b56e8efa17edbdcaba) Native mods: a cancelled key still types the characters left, and the socket's backspace stays a key - [`9d255bb`](https://github.com/horizon-rust/horizon/commit/9d255bbdf003002a2a1c2e5fe4e7df0bfc60e88b) Merge branch 'screen-mouse-scrolled' into screen-key-input - [`f750400`](https://github.com/horizon-rust/horizon/commit/f75040061d13d3f7ae31af692be198b1f2e957c4) Native mods: a key's characters reach the screen after the key has acted - [`885a33e`](https://github.com/horizon-rust/horizon/commit/885a33e93059f75a8ad0ccb3dc173d43ff031af2) Native mods: the world options boxes type a key's characters only - [`bbc31dd`](https://github.com/horizon-rust/horizon/commit/bbc31dd472e5ecbd89a2de2fba34b86bccc5c604) Merge remote-tracking branch 'hr/main' into pr-5617 - [`8560cb7`](https://github.com/horizon-rust/horizon/commit/8560cb7287f6a520193ee4758e412277630cafa5) Creative search: a number key the hovered slot took types nothing; scroll hook doc: discrete scrolling, scroll-at - [`2f077e8`](https://github.com/horizon-rust/horizon/commit/2f077e899b0a0c14daf91766b75ef7427d00e513) Merge remote-tracking branch 'hr/main' into pr-5617 ### 📊 Changes **7 files changed** (+410 additions, -56 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+67 -1) 📝 `crates/horizon-client/src/game/control.rs` (+88 -42) 📝 `crates/horizon-client/src/game/ime.rs` (+7 -0) 📝 `crates/horizon-client/src/game/lan_screen.rs` (+15 -4) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+223 -8) ➕ `tools/native-hook-fragments/screen_key_input.json` (+9 -0) 📝 `tools/native-hook-fragments/screen_mouse_scrolled.json` (+1 -1) </details> ### 📄 Description > 🤖 Opened by Sylviromi's AI agent (Claude Code, claude-sonnet-5-5), not by Sylviromi personally. Part of #5543 (keys and typed characters; with this the set of six screen hooks is complete). Stacked on #5616, which is stacked on #5578: the commits up to the merge of #5616's branch are theirs; this PR's own commit is `7a6468bd8` (plus the merge `dd72fb827` that brings #5616 forward). Review `7a6468bd8` only; after #5616 merges this diff is ~215 lines. ## What and why Adds `native_screen_key_pressed_pre` and `native_screen_char_typed_pre` (NeoForge `ScreenEvent.KeyPressed.Pre` / `CharacterTyped.Pre`), so a native mod can take a key or a typed character on an open screen before the game does. Hook API: next. - `native_screen_key_pressed_pre(&self, screen: &NativeScreenView, key: &str, repeat: bool, modifiers: u32, canceled: &mut bool)`. `key` is vanilla's key name (`key.keyboard.e`, the name `native_key` hands over; a key with no name fires nothing). `repeat` marks the keyboard's auto-repeat (Horizon's extra; NeoForge folds repeats into the event). - `native_screen_char_typed_pre(&self, screen: &NativeScreenView, c: char, modifiers: u32, canceled: &mut bool)`. - A cancelled press goes no further: no focus move, no Escape-close, no inventory or hotbar key, no text box, no `native_key`. Its release still arrives, so a `native_key` listener sees a release without its press. - A cancelled character drops only that character and never reaches a text box. Characters fire even when the press was cancelled, as vanilla delivers `charTyped` anyway; control characters (Enter, Backspace, Tab, Delete, Escape, a Control letter) are keys and fire nothing. - Fired from the window's key event (after the fullscreen, screenshot, debug and narrator keys), and also from the control socket's `key` and `type` commands and the input method's committed text, so the same hooks cover every way text reaches a screen. - Same gate as the mouse hooks: Options and the pack list opened from the title screen fire; the title screen itself, connect/loading screens, prompts/books/sign editors over gameplay and a world loading or saving never do. - Pending fragment: `tools/native-hook-fragments/screen_key_input.json`. ## In-game proof A test native mod cancelled keys on the open screen, built into the game and run offscreen: pressing E on the open inventory was cancelled and the inventory stayed open, while Escape went through and closed it. Typing "axb" in chat with 'x' cancelled left "ab". No screenshot: the hook has no visuals of its own. ## Kind - [x] feature: something new for players (listed under New in the release notes) Label: feature ## Vanilla reference NeoForge `ScreenEvent.KeyPressed.Pre` / `CharacterTyped.Pre`, fired from `KeyboardHandler.keyPress` / `charTyped` before `Screen.keyPressed` / `charTyped`. There is no parity harness for this ticket (it adds hooks, no vanilla behaviour changes). ## Other projects' code none ## Self-check Note: the pr_ready run below covers this PR and #5616 together, against `screen-mouse-button`; the scope counts both. **pr_ready** (`tools/pr_ready.py --quick`) | Check | Result | | --- | --- | | Scope | ✅ 6 files, +275 −4 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 510 passed | | rustfmt | ✅ | | clippy | ✅ | | tests: horizon-client | ✅ 1580 passed | | doc tests | ✅ | | launcher | ➖ launcher untouched | | Parity | ➖ not run locally: CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | "Allow edits by maintainers" is on (default for fork PRs). 🤖 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 06:19:49 +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#6390
No description provided.