Input: a key tapped between two asks is still seen at a frame a second; the scripted keys' hold can be set #1101

Open
Dathinel wants to merge 4 commits from upstream-pr/1104 into main
Dathinel commented 2026-11-25 19:31:43 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Dathinel on 2026-11-25T19:31:43Z.


What

Two small changes in crates/victory-hle/src/modules/gameinput.rs (+13 −3) for runs at about a frame a second, which is where a 4 GB card is in the world today.

  1. A key tapped between two asks is still seen. The title asks for input once a frame. Host::keys reported only keys that were down at that instant (GetAsyncKeyState(vk) < 0), so at 1 fps a normal tap, down and up inside the second between two asks, never reached the title: menus and prompts needed the key held for over a second. It now also takes the low bit of GetAsyncKeyState (pressed since the last query), so such a tap shows as down for one ask. Still only while the title's window has focus.
  2. VICTORY_KEYS_HOLD_MS (diagnostics builds): the scripted keys of VICTORY_KEYS are held 0.2 s; at 1 fps that falls between two asks the same way. The variable sets the hold; unset, it stays 0.2 s.

Measured

RTX 3050 Laptop 4 GB, Ryzen 7 7435HS, Windows 11 26200, --console series-s, on d510ee4 with #1081 and #798 merged.

  • cargo test --locked -p victory-hle --lib gameinput, with and without --features diagnostics: 7 passed, on this branch (dd3a14b + this commit).
  • A scripted run before the change (VICTORY_KEYS with Enter every 8 to 15 s, 0.2 s holds): the person at the machine had to press Enter by hand to get through the screens once the frame rate dropped.
  • A scripted run after it, with VICTORY_KEYS_HOLD_MS=1500: the run went from boot into the opening (330 s) with the same key list.

Not tested

  • A physical keyboard tap at 1 fps after the change: I could not watch one, and I cannot rule out that someone pressed a key during the second scripted run. A check from anyone with a slow world frame would be welcome.
  • The low bit of GetAsyncKeyState can also carry a press made just before the window took focus; I did not look for a case where that matters.
  • Pads (XInput) are not touched.

AI-assisted (Claude Code). No game data attached.


Update, 28 November. Merged current main into the branch (it conflicted after the rebase of this fork). main's scripted keys now carry their own from-to ranges and a keys file, so the VICTORY_KEYS_HOLD_MS part is dropped: what remains is 15 lines, the tap itself and the focus guard from the review. cargo check -p victory-hle passes; not run in the game on this base.

Where this came from and what it was measured on (RTX 3050 Laptop 4 GB, Series S, runs at 1 to 7 fps where a tap between two asks was lost): https://github.com/Dathinel/victory-4gb

<!-- greyfinch-sync:fxceless/victory-fork:issue:5497816137 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1104). Originally posted by [Dathinel](https://github.com/Dathinel) on 2026-11-25T19:31:43Z. --- ## What Two small changes in `crates/victory-hle/src/modules/gameinput.rs` (+13 −3) for runs at about a frame a second, which is where a 4 GB card is in the world today. 1. **A key tapped between two asks is still seen.** The title asks for input once a frame. `Host::keys` reported only keys that were down at that instant (`GetAsyncKeyState(vk) < 0`), so at 1 fps a normal tap, down and up inside the second between two asks, never reached the title: menus and prompts needed the key held for over a second. It now also takes the low bit of `GetAsyncKeyState` (pressed since the last query), so such a tap shows as down for one ask. Still only while the title's window has focus. 2. **`VICTORY_KEYS_HOLD_MS`** (diagnostics builds): the scripted keys of `VICTORY_KEYS` are held 0.2 s; at 1 fps that falls between two asks the same way. The variable sets the hold; unset, it stays 0.2 s. ## Measured RTX 3050 Laptop 4 GB, Ryzen 7 7435HS, Windows 11 26200, `--console series-s`, on d510ee4 with #1081 and #798 merged. - `cargo test --locked -p victory-hle --lib gameinput`, with and without `--features diagnostics`: 7 passed, on this branch (dd3a14b + this commit). - A scripted run before the change (`VICTORY_KEYS` with Enter every 8 to 15 s, 0.2 s holds): the person at the machine had to press Enter by hand to get through the screens once the frame rate dropped. - A scripted run after it, with `VICTORY_KEYS_HOLD_MS=1500`: the run went from boot into the opening (330 s) with the same key list. ## Not tested - A physical keyboard tap at 1 fps after the change: I could not watch one, and I cannot rule out that someone pressed a key during the second scripted run. A check from anyone with a slow world frame would be welcome. - The low bit of `GetAsyncKeyState` can also carry a press made just before the window took focus; I did not look for a case where that matters. - Pads (XInput) are not touched. AI-assisted (Claude Code). No game data attached. --- **Update, 28 November.** Merged current `main` into the branch (it conflicted after the rebase of this fork). `main`'s scripted keys now carry their own from-to ranges and a keys file, so the `VICTORY_KEYS_HOLD_MS` part is dropped: what remains is 15 lines, the tap itself and the focus guard from the review. `cargo check -p victory-hle` passes; not run in the game on this base. Where this came from and what it was measured on (RTX 3050 Laptop 4 GB, Series S, runs at 1 to 7 fps where a tap between two asks was lost): https://github.com/Dathinel/victory-4gb
chatgpt-codex-connector[bot] commented 2026-11-25 19:31:53 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T19:31:53Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T01:10:30.242670Z 7651d4f New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7172425539 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1104#issuecomment-7172425539). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-25T19:31:53Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"7651d4fff4323657b60dbb1fa33d87d04fa42296","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-28T01:10:30.242670Z">2026-11-28T01:10:30.242670Z</relative-time> | `7651d4f` | New commits | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
chatgpt-codex-connector[bot] commented 2026-11-25 19:35:22 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T19:35:22Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 25c50f18f7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:fxceless/victory-fork:review:6063813375 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1104#pullrequestreview-6063813375). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-25T19:35:22Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `25c50f18f7` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
Dathinel commented 2026-11-25 20:09:30 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Dathinel on 2026-11-25T20:02:22Z.


The review's point holds: with focus away, keys() does not query the keys, so the low bit could carry a press made in another window into the first look after focus returns. Fixed in 5ea4ed5: Host remembers whether the last look had focus, and the first look after it comes back takes only keys that are down at that instant (it still queries, which clears the stale bits). The first look of a run counts as such too. cargo test --locked -p victory-hle --lib gameinput, with and without diagnostics: 7 passed; clippy on victory-hle clean. Not tested by hand with a second window.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7173101461 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1104#issuecomment-7173101461). Originally posted by [Dathinel](https://github.com/Dathinel) on 2026-11-25T20:02:22Z. --- The review's point holds: with focus away, `keys()` does not query the keys, so the low bit could carry a press made in another window into the first look after focus returns. Fixed in `5ea4ed5`: `Host` remembers whether the last look had focus, and the first look after it comes back takes only keys that are down at that instant (it still queries, which clears the stale bits). The first look of a run counts as such too. `cargo test --locked -p victory-hle --lib gameinput`, with and without `diagnostics`: 7 passed; clippy on `victory-hle` clean. Not tested by hand with a second window.
chatgpt-codex-connector[bot commented 2026-11-25 20:09:31 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T19:35:22Z.

Code review location: crates/victory-hle/src/modules/gameinput.rs; line 1179

@@ -1171,8 +1171,13 @@ mod host {
                 // mouse buttons (below 0x08).
                 let held: Vec<u8> = (0x08..=0xFE_u8)
                     .filter(|vk| !(0x10..=0x12).contains(vk) && !down.contains(vk))
+                    // Down now, or pressed since the last look (the low bit): a title that
+                    // asks once a frame at a frame a second still sees a tap between two asks.
                     // SAFETY: plain queries.
-                    .filter(|&vk| unsafe { GetAsyncKeyState(i32::from(vk)) } < 0)
+                    .filter(|&vk| {
+                        let state = unsafe { GetAsyncKeyState(i32::from(vk)) };
+                        state < 0 || state & 1 != 0

P2 Badge Discard historical presses when regaining focus

On Windows, pressing and releasing Enter or Esc in another application can now generate input when returning to the title. keys() skips GetAsyncKeyState while focused() is false, so the low bit can retain a background press until the first focused poll. This condition then reports the already-released key as down; with no controller connected, fallback() also maps it to an A/Menu button press, potentially confirming a prompt or toggling pause merely by refocusing. Discard historical pressed bits on focus regain before accepting them as title input.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:fxceless/victory-fork:review-comment:4699914745 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1104#discussion_r4699914745). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T19:35:22Z. **Code review location:** `crates/victory-hle/src/modules/gameinput.rs`; line 1179 ~~~~diff @@ -1171,8 +1171,13 @@ mod host { // mouse buttons (below 0x08). let held: Vec<u8> = (0x08..=0xFE_u8) .filter(|vk| !(0x10..=0x12).contains(vk) && !down.contains(vk)) + // Down now, or pressed since the last look (the low bit): a title that + // asks once a frame at a frame a second still sees a tap between two asks. // SAFETY: plain queries. - .filter(|&vk| unsafe { GetAsyncKeyState(i32::from(vk)) } < 0) + .filter(|&vk| { + let state = unsafe { GetAsyncKeyState(i32::from(vk)) }; + state < 0 || state & 1 != 0 ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Discard historical presses when regaining focus** On Windows, pressing and releasing Enter or Esc in another application can now generate input when returning to the title. `keys()` skips `GetAsyncKeyState` while `focused()` is false, so the low bit can retain a background press until the first focused poll. This condition then reports the already-released key as down; with no controller connected, `fallback()` also maps it to an A/Menu button press, potentially confirming a prompt or toggling pause merely by refocusing. Discard historical pressed bits on focus regain before accepting them as title input. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot] commented 2026-11-28 01:10:27 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-28T01:10:27Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7651d4fff4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:fxceless/victory-fork:review:6094827240 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1104#pullrequestreview-6094827240). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-28T01:10:27Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `7651d4fff4` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
chatgpt-codex-connector[bot] commented 2026-11-28 01:10:28 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-28T01:10:28Z.

Code review location: crates/victory-hle/src/modules/gameinput.rs; line 1318

@@ -1298,13 +1301,22 @@ mod host {
                 return Vec::new();
             }
             let mut down = scripted();
-            if focused() {
+            let focused = focused();
+            // A press from before the window had focus is not the title's: the first look
+            // after focus returns reads the low bits only to clear them.
+            let fresh = focused && !std::mem::replace(&mut self.focused, focused);
+            if focused {
                 // Left/right modifier keys only, as devices report them; no
                 // mouse buttons (below 0x08).
                 let held: Vec<u8> = (0x08..=0xFE_u8)
                     .filter(|vk| !(0x10..=0x12).contains(vk) && !down.contains(vk))
-                    // SAFETY: plain queries.
-                    .filter(|&vk| unsafe { GetAsyncKeyState(i32::from(vk)) } < 0)
+                    // Down now, or pressed since the last look (the low bit): a title that
+                    // asks once a frame at a frame a second still sees a tap between two asks.
+                    .filter(|&vk| {
+                        // SAFETY: a plain query.
+                        let state = unsafe { GetAsyncKeyState(i32::from(vk)) };
+                        state < 0 || (!fresh && state & 1 != 0)

P2 Badge Discard buffered keypresses after the F1 menu closes

On Windows with the default one-pad mode, tapping and releasing Backspace while the F1 settings menu is open can generate a B press after the menu closes. keys() returns before querying keys during menu capture, and the settings worker only queries F1/arrows/Enter/Esc (crates/victory-gpu/src/host/menu.rs:140), leaving Backspace's historical press bit uncleared. Closing the menu does not change process focus, so fresh is false and this condition publishes the released key to the keyboard and fallback() gamepad. This can cancel a title prompt despite the menu's keyboard suppression. Clear historical bits during capture or discard them on the first poll after capture ends.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:fxceless/victory-fork:review-comment:4724803135 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1104#discussion_r4724803135). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-28T01:10:28Z. **Code review location:** `crates/victory-hle/src/modules/gameinput.rs`; line 1318 ~~~~diff @@ -1298,13 +1301,22 @@ mod host { return Vec::new(); } let mut down = scripted(); - if focused() { + let focused = focused(); + // A press from before the window had focus is not the title's: the first look + // after focus returns reads the low bits only to clear them. + let fresh = focused && !std::mem::replace(&mut self.focused, focused); + if focused { // Left/right modifier keys only, as devices report them; no // mouse buttons (below 0x08). let held: Vec<u8> = (0x08..=0xFE_u8) .filter(|vk| !(0x10..=0x12).contains(vk) && !down.contains(vk)) - // SAFETY: plain queries. - .filter(|&vk| unsafe { GetAsyncKeyState(i32::from(vk)) } < 0) + // Down now, or pressed since the last look (the low bit): a title that + // asks once a frame at a frame a second still sees a tap between two asks. + .filter(|&vk| { + // SAFETY: a plain query. + let state = unsafe { GetAsyncKeyState(i32::from(vk)) }; + state < 0 || (!fresh && state & 1 != 0) ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Discard buffered keypresses after the F1 menu closes** On Windows with the default one-pad mode, tapping and releasing Backspace while the F1 settings menu is open can generate a B press after the menu closes. `keys()` returns before querying keys during menu capture, and the settings worker only queries F1/arrows/Enter/Esc (`crates/victory-gpu/src/host/menu.rs:140`), leaving Backspace's historical press bit uncleared. Closing the menu does not change process focus, so `fresh` is false and this condition publishes the released key to the keyboard and `fallback()` gamepad. This can cancel a title prompt despite the menu's keyboard suppression. Clear historical bits during capture or discard them on the first poll after capture ends. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Dathinel commented 2026-11-28 01:11:51 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Dathinel on 2026-11-28T01:11:51Z.


The red check is not from this change: Clippy stops at crates/victory-formats/src/texture.rs:1346 ("operator precedence might not be obvious"), a file this PR does not touch, and the last two CI runs on main itself fail too. The branch now merges cleanly. Written with AI assistance (Claude Code).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7231491192 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1104#issuecomment-7231491192). Originally posted by [Dathinel](https://github.com/Dathinel) on 2026-11-28T01:11:51Z. --- The red check is not from this change: Clippy stops at `crates/victory-formats/src/texture.rs:1346` ("operator precedence might not be obvious"), a file this PR does not touch, and the last two CI runs on `main` itself fail too. The branch now merges cleanly. Written with AI assistance (Claude Code).
Dathinel commented 2026-11-28 04:48:45 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Dathinel on 2026-11-28T04:48:45Z.


The review's point holds (a key tapped while the F1 settings menu has the keyboard came out as a press once it closed, since closing the menu does not change focus). Fixed in the last commit: while the menu is open the look counts as focus away, so the first look after it closes only clears the low bits. cargo check -p victory-hle passes. Written with AI assistance (Claude Code).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7234274334 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1104#issuecomment-7234274334). Originally posted by [Dathinel](https://github.com/Dathinel) on 2026-11-28T04:48:45Z. --- The review's point holds (a key tapped while the F1 settings menu has the keyboard came out as a press once it closed, since closing the menu does not change focus). Fixed in the last commit: while the menu is open the look counts as focus away, so the first look after it closes only clears the low bits. `cargo check -p victory-hle` passes. Written with AI assistance (Claude Code).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1104:upstream-pr/1104'
git switch 'upstream-pr/1104'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1104'
git switch 'upstream-pr/1104'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1104'
git switch 'upstream-pr/1104'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1104'
git switch 'main'
git merge --squash 'upstream-pr/1104'
git switch 'main'
git merge --ff-only 'upstream-pr/1104'
git switch 'main'
git merge 'upstream-pr/1104'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
fxceless/victory-fork!1101
No description provided.