fix(runner): Harden centralized keyboard hook against stuck keys#8
fix(runner): Harden centralized keyboard hook against stuck keys#8crutkas wants to merge 1 commit into
Conversation
This comment has been minimized.
This comment has been minimized.
|
Quick check on the new injection filter ( if ((keyPressInfo.flags & LLKHF_INJECTED) && keyPressInfo.dwExtraInfo == 0)
{
return CallNextHookEx(hHook, nCode, wParam, lParam);
}This skips any injected event that does not carry a non-zero
If any of those rely on the centralized hook to surface PowerToys hotkeys (e.g. user triggers a PT shortcut via OSK), this becomes a silent accessibility regression that only surfaces in the field. A manual smoke note in the PR body "verified Win+ via OSK still triggers" would close it out cleanly. |
- Tag dummy 0xFF SendInput with dwExtraInfo to prevent cross-hook interference - Skip LLKHF_INJECTED events from OSK/macro tools (dwExtraInfo==0) - Revalidate key state in PressedKeyTimerProc before firing action - Kill pending timers and reset state in Stop() - Make vkCodePressed atomic to fix data race Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1fd96dc to
61b7234
Compare
|
Removed the injected-event filter entirely rather than narrowing it. The hook already passes PowerToys' own injected events through at the top of The actual hardening stays: atomic |
|
Superseded by the upstream PR against microsoft/PowerToys: microsoft#48570 (rebased onto current main, builds/tests verified). Closing this intra-fork review PR. |
Summary
Harden the centralized keyboard hook (
centralized_kb_hook.cpp) against stuck keys, ghost activations, and cross-hook interference.Changes
B1: Tag dummy 0xFF SendInput with
dwExtraInfoThe dummy keystroke injected after hotkey actions had no
dwExtraInfotag, causing other hooks (KBM, PowerAccent) to process it as real input. Now tagged withCENTRALIZED_KEYBOARD_HOOK_DONT_TRIGGER_FLAG.B2: Add
LLKHF_INJECTEDearly-outSkip all injected events not tagged by PowerToys. Prevents On-Screen Keyboard, AutoHotkey, KVM switches, and other macro tools from driving the hotkey/pressed-key state machines.
B3: Revalidate key state in
PressedKeyTimerProcCheck
GetAsyncKeyStatebefore firing the timer action. Prevents ghost activations when the user releases the key before the timer fires.B4: Harden
Stop()Kill all pending pressed-key timers and reset
vkCodePressedbefore unhooking. Prevents stale state after module disable/re-enable.B5: Fix
vkCodePressedrace conditionsvkCodePressedanstd::atomic<DWORD>pressedKeyMutexto cover the entire pressed-key block (TOCTOU fix)0x100withVK_DISABLEDHow to Reproduce
How to Verify
PR Checklist