fix(hid): HOS_INPUT_SCRIPT_BACKGROUND no longer lets the player's keyboard into a test run #319
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/upscaling
beanstalk: approved @ 1697603
beanstalk: approved @ 2c5a62e
beanstalk: approved @ 4fd82b7
beanstalk: approved @ 64d6d09
beanstalk: approved @ 6f91fae
beanstalk: approved @ 70a78f9
beanstalk: approved @ 8d361dc
beanstalk: approved @ 9d8356e
beanstalk: approved @ abf2227
beanstalk: approved @ d82f202
beanstalk: approved @ e5f1e40
beanstalk: approved @ ee8ab5f
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
testing wanted
ci: approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!319
Loading…
Reference in a new issue
No description provided.
Delete branch "d4nkn3ss/Longshot:fix/input-script-background"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type: fix · Risk: low · Tested on: Windows 11, RTX 3080 · Needs: none
Why
A test run started with
HOS_INPUT_SCRIPT_BACKGROUND=1takes the keyboard of whoever is using the PC, even when its window is behind another one. Typing in another window, even in a chat, moves Link, makes him jump, and Enter pauses the game, which spoils the run. I searched the tracker (forge.py issue list --state all) and found no issue for this. The switch came from https://github.com/NotRexed/Hookshot/issues/389.How to reproduce
Seen on: Windows 11 Pro 26300, RTX 3080 10 GB, NVIDIA 621.14
Settings and switches: defaults;
HOS_INPUT_SCRIPT_BACKGROUND=1,HOS_INPUT_LIVE=<file>,HOS_SKIP_OPENING=1, a window that never takes focus (scripts/run-vk.ps1 -Window)Steps: append
0:Alines to the live file until the test save is in play, then click into another window and press Enter, hold W, type in a chatExpected: the game behind ignores the keys; only the script's presses reach it
Actual: each Enter pauses the game (
control: state play -> menu), and Link walks and jumps while the user types elsewhereWhat changed
With
HOS_INPUT_SCRIPT_BACKGROUNDset, the game no longer skips the "is my window in front" check, so the player's keyboard and mouse stay out of a game behind another window. Scripted and control-bridge presses never needed the switch: they are put in before that check. The switch now only writes a log line saying it is no longer needed.read_input()inhost/nn_hid.ckeeps the focus gate with the switch set.scripted_input()andhos_control_input()add their presses before the gate, so they already count with the window behind (the existingscript-backgroundcase). Skipping the gate let through only the player's devices: the keyboard (GetAsyncKeyStatesees every key whatever window is in front, so headless runs too) and the mouse.tests/test_input_background.pygets a case,script-background-switch: the window behind, the switch set, a bound key held. It fails on main and passes here.docs/development.md; the two runs below as files indocs/tested/.Measurements
Verdict: fixed: Enter pressed in other windows paused the game 3 times on main and 0 times with this PR, and Link no longer moves while the user types elsewhere; the new game-free case fails on main
aa95d35fand passes on this PR @dbf3a2d1.Baseline: the in-game A/B ran on 2026-11-13, main @
fbd42024(itshost/nn_hid.cas514591a3) against this PR @ 3fb77017. The PR has since been rebased onto mainaa95d35f. Main has changedhost/nn_hid.csince then (the Walk key, #66), but not the lines this PR changes, and the game-free case below reruns the comparison on the current commits: it fails on mainaa95d35fand passes ondbf3a2d1.Hardware: Windows 11 Pro 26300, RTX 3080 10 GB, NVIDIA 621.14, i9-12900K, 64 GB
Scene: the test save, in play, a window that never takes focus (
scripts/run-vk.ps1 -Window), default settingsMethod: a behaviour check, one run each with the user at the keyboard. The script presses A into the save, then stops; the user presses Enter twice in other windows, holds W, and types in a chat window. Counted: the
control: state play -> menulines inlongshot_log.txt, and what the user saw. Each run,tests/test_input_background.py'sscript-background-switchcase repeats it game-free.How to reproduce:
scripts/run-vk.ps1 -Window -Env "HOS_INPUT_SCRIPT_BACKGROUND=1;HOS_INPUT_LIVE=<file>;HOS_SKIP_OPENING=1", append0:Alines to the file until in play, then click into another window and press Enter.fbd42024aa95d35fdbf3a2d1test_input_background.pywith thescript-background-switchcasefixture.exe script-background-switchexits 1: the bound key reaches the game behind)Flags and settings
This PR changes what one test switch does:
HOS_INPUT_SCRIPT_BACKGROUNDno longer lets the player's devices through.HOS_INPUT_SCRIPT_BACKGROUNDTesting
Tested:
python -I -B tests/run_all.pyon Windows 11 (llvm-mingw from the Longshot Builder), on this PR @dbf3a2d1and on main @aa95d35f: 541 passed, 17 failed, 35 skipped on both, and the same 17 fail on both:test_appimage_player_build,test_cpm_discovery,test_cpp_preflight,test_crash_dialog,test_env_on,test_lift_cleanup_error,test_linux_preflight,test_make_game_cache,test_make_game_prepare,test_missing_nup,test_oot_state_tap,test_options_budget_once,test_readback_late,test_release,test_tested_configurations(its CRLF pipe case),test_vk_pgo,test_walk_key(undefined symbol: hos_oot_autoload_input, on main too).host/nn_hid.c, 18 pass,test_walk_keyfails as on main (above), andtest_pipeline_tourgave no result (it stops on "the tour's run is not given --vk-profile", on main too).Not tested:
host/nn_hid.cdiff drops one condition (&& !scripted_background) and changes a log string, with no new call, header or path, so it builds wherever main does; built on Windows (llvm-mingw, the game and the test fixture).read_input()gate, so it should behave the same. I didn't run it.HOS_INPUT_BACKGROUNDand the menu's "Controller in background" row, as without the switch (thepads-envandpads-menucases cover it game-free).Must be tested: None. The game-free case covers the change on every run, and the in-game check is above.
Risks
What could break: a script that counted on the switch to let a person's keyboard or mouse into a game behind another window loses that. Nothing in this repository sets it.
Turning it off: revert the commit.
Compatibility: Nothing changes for a player: the switch is for test runs only, and saves,
longshot_options.ini, the caches and the vk ABI are untouched.The window counts as in front while a tool window or overlay is in front (the taskbar, a notification) if the game was the last normal window in front:
game_in_front(). So a test window someone clicked into still takes their keys after they click the taskbar. That is the player's case and is unchanged here.Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.docs/tested/for each new measured run (format indocs/tested-configurations.md).mainand passing here.tests/that reads changed source updated in this PR, not weakened.🤖 Generated with Claude Code
2a8f33153238f9d90fb638f9d90fb696f3047d7296f3047d720268a234ca0268a234ca5dee9c7b545dee9c7b54e5b4789ef4e5b4789ef4d6b5679f4ad6b5679f4aab6deafc31ab6deafc31dbf3a2d14cRebased onto main
aa95d35f(dbf3a2d1). The two runs moved from the frozen table in docs/tested-configurations.md to files in docs/tested/, as the tested-runs rule now asks. run_all: 541 passed, 17 failed on both mainaa95d35fand this PR, with the same 17 failing (named under Testing). The new case fails on mainaa95d35fand passes here. Description rewritten to the current template.WIP: fix(hid): HOS_INPUT_SCRIPT_BACKGROUND no longer lets the player's keyboard into a test runto fix(hid): HOS_INPUT_SCRIPT_BACKGROUND no longer lets the player's keyboard into a test runView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.