Conversation
`send_input_safe` retried `SendInput` in a tight loop until it reported success. Windows refuses an injection in some cases, most commonly while a higher integrity window has focus, and then `SendInput` returns zero every time, so the loop never ends. The call is synchronous, so the whole emulation task stays stuck in it. No further input is sent, and the cleanup that releases held keys cannot run either, because it injects through the same path. The key repeat task could spin the same way. Give up after a bounded number of attempts and return an error, and stop the repeat task when the injection fails. The error reaches the dispatcher, which ends the emulation session, so it is recoverable by re-enabling emulation instead of freezing.
minh-tg
marked this pull request as ready for review
September 29, 2026 09:08
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Windows can refuse an injected event, most often when a higher integrity window has focus.
SendInputreturns zero every time that happens, and the old code retried it in a tight loop until it succeeded, so it never stopped.That call is synchronous, so the whole emulation task sat inside it. No more input went out, and the cleanup that releases held keys couldn't run either, because it injects through the same path. The key repeat task had the same problem.
What changed in
input-emulation/src/windows.rs:DOC.mdgets one line.Before, a refused injection froze lan-mouse until you killed it. After, emulation stops and says so, and you can turn it back on. Input isn't delivered while it's stopped, but that is what happens when Windows won't let us inject.
Testing:
cargo fmt --all --checkcargo test --workspace --all-featurescargo check --workspace --all-targets --all-featurescargo clippy --workspace --all-targets --all-features -- -D warningsgit diff --checkcargo check -p input-emulation --no-default-features --target x86_64-pc-windows-msvc, using a temporary toolchain with the Windows target installed. I checked that this covers the file by putting a type error in it first, and the error showed up.Gaps:
Came out of #510 when I trimmed it. Otherwise unrelated.