Repository navigation
M3: hold stray keys - #1
Merged
Merged
Conversation
…window A low-level keyboard hook on its own thread holds keys typed while focus is on a window Staypaw hasn't judged yet. After a restore they're replayed into your window; for a game (the protected app, an exe Windows' Game Bar lists, or an app Staypaw can't name) or a change that stands, they're dropped. A hold that makes no progress for 500 ms gives up. Work in progress: the live key test still loses a key now and then.
BringWindowToTop's own activation could leave no window in front during a restore. In a steal test that types without pause, about 40 of 1,000 keys then reached no window, and each steal logged two Restored rows, counting twice toward the fight limit. SetForegroundWindow raises the window anyway.
After a steal, SetForegroundWindow on your window can return true and still leave no window in front: the switch to your window's thread never completes. Your keys then go nowhere, the log says Restored, and the stealer can't even steal again. A plain retry never fixed it. While no window is in front, the 15 ms check now retries the restore, for as long as held keys wait (500 ms), with Staypaw's thread sharing the input of your window's thread instead of the stealer's, so the switch happens at once. That recovered 17 of 17 such restores. A hung window is skipped, since sharing its input would hang Staypaw too, and the no-op key fallback isn't sent when no stealer is in front to receive it.
A key still unread in your window when a stealer joins its input with AttachThreadInput and takes focus goes to the stealer, or nowhere, and no hook can hold it back: tagged keys showed every such key was let through 0-3 ms before the steal, while your window had focus. The test's typing and the stealer's 400 ms timer woke on the same system tick, so it failed now and then. The steal tool now also steals when its thread gets WM_APP. The test types into your window, goes quiet for 30 ms, asks for a steal, and types three keys before Staypaw can judge it, 15 times 400 ms apart. The exact checks stay: no key reaches the stealer and every key reaches your window. With key holding turned off, the stealer got 36 of the 45 keys and it failed.
Tick M3 with its evidence, and record the held-key rules, the restore without BringWindowToTop, the restore finished from your window's thread, and the keys no hook can hold. The trust contract names that one shared input, and the README no longer calls holding keys in progress.
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.
Finishes M3 in
ROADMAP.md: aWH_KEYBOARD_LLhook on its own thread holds keys typed during a steal, replays them into your window after the restore, and drops them for a game.BringWindowToTop, which could leave no window in front, and a restore that does end with no window in front is finished from your window's thread.StealTestspassed three runs in a row (45 keys held during 15 steals, none reached the stealer, all 120 reached your window). A Defender scan of the published exe was clean.The decisions, with what each gives up, are in
ROADMAP.mdunder 2026-10-24.