[PowerAccent] Fix injection hygiene and reset state on focus loss#48572
[PowerAccent] Fix injection hygiene and reset state on focus loss#48572crutkas wants to merge 3 commits into
Conversation
- Filter LLKHF_INJECTED events in LL hook to prevent cross-module triggers - Tag all SendInput output with dwExtraInfo for cross-hook identification - Add ForceReset() for focus-loss cleanup - Replace SendKeys.SendWait with tagged SendInput for arrow keys Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Selector_Deactivated now calls ForceReset, so losing focus mid-accent clears any half-pressed state instead of leaving the toolbar or shift modifiers stuck. OnKeyDown/OnKeyUp run on the low-level keyboard hook thread while ForceReset runs on the UI thread. The PowerAccent.cs callbacks Dispatcher.Invoke synchronously onto that UI thread, so holding a lock across the hook callbacks would deadlock against ForceReset. The shared flags and letterPressed are therefore std::atomic rather than mutex-guarded - race-free and lock-free on the hot hook path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
PowerAccent injects VK_LEFT / VK_RIGHT to move the caret while selecting an accent. Without KEYEVENTF_EXTENDEDKEY the synthesized arrow keys carry the non-extended scan code, which some apps interpret as numpad navigation (affected by NumLock) rather than the dedicated arrow cluster. Set the extended-key flag on both the key-down and key-up INPUTs, matching how WinForms SendKeys synthesizes these keys. Also resolve two StyleCop errors in code this change set introduced, so the project builds clean: rename the POWERTOYS_INJECTED_TAG constant to PascalCase PowerToysInjectedTag (SA1310) and add the required blank line after the backspace send-failure check (SA1513). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@check-spelling-bot Report🔴 Please reviewSee the 📂 files view, the 📜action log, 👼 SARIF report, or 📝 job summary for details.
See ❌ Event descriptions for more information. Some files were automatically ignored 🙈These sample patterns would exclude them: You should consider adding them to: File matching is via Perl regular expressions. To check these files, more of their words need to be in the dictionary than not. You can use To update file exclusions, you could run the following commands... in a clone of the git@github.com:crutkas/autoUpgradeAttempt.git repository curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/cfb6f7e75bbfc89c71eaa30366d0c166f1bd9c8c/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/27451220763/attempts/1' &&
git commit -m 'Update check-spelling metadata'Forbidden patterns 🙅 (1)In order to address this, you could change the content to not match the forbidden patterns (comments before forbidden patterns may help explain why they're forbidden), add patterns for acceptable instances, or adjust the forbidden patterns themselves. These forbidden patterns matched content: Should be
|
Summary
Fixes PowerAccent injection hygiene and a stuck accent-menu state when the selector loses focus.
What this changes
SendKeys.SendWait("{LEFT}"/"{RIGHT}")withWindowsFunctions.SendArrowKey(VK_LEFT/VK_RIGHT), which setsKEYEVENTF_EXTENDEDKEYon both the down and up events. Without it the synthesized arrows carry the non-extended scan code and some apps treat them as NumLock-dependent numpad navigation instead of the arrow cluster.dwExtraInfo = 0x110, mirroringCENTRALIZED_KEYBOARD_HOOK_DONT_TRIGGER_FLAG) so PowerAccent's own injections can't re-trigger other shortcuts.ForceReset()(added to theKeyboardListenerWinRT type/IDL) is wired to the selector'sDeactivatedevent, so the accent menu can't be left stuck if focus is taken mid-selection.std::atomic. They are written from the low-level hook thread (OnKeyDown/OnKeyUp) and from the UI/Dispatcher thread (ForceReset). A mutex is intentionally avoided: theOnKeyDown/OnKeyUpcallbacksDispatcher.Invokeonto the UI thread whereForceResetruns, so a lock held across them would deadlock.Testing
main. StyleCop passes.This is one of a small set of related "stuck key" hardening fixes; each stands alone.