CmdPal: Fix crash on summon when UseLowLevelGlobalHotkey is enabled#47409
Draft
Copilot wants to merge 2 commits into
Draft
CmdPal: Fix crash on summon when UseLowLevelGlobalHotkey is enabled#47409Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
When UseLowLevelGlobalHotkey is enabled, the ProcessCommand callback is invoked directly from the WH_KEYBOARD_LL low-level keyboard hook, which is an input-synchronous context. Calling ShowWindow/Hide from that context triggers WinUI COM calls that COM forbids inside input-sync calls, causing RPC_E_CANTCALLOUT_ININPUTSYNCCALL (0x8001010D). Fix: wrap the callback with DispatcherQueue.TryEnqueue so HandleSummon runs on the UI thread after the hook callback returns. Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/17ab0175-9459-4b42-928e-5f7f27b97f6a Co-authored-by: MuyuanMS <116717757+MuyuanMS@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix CmdPal crash on summon
CmdPal: Fix crash on summon when UseLowLevelGlobalHotkey is enabled
Apr 29, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a crash when Command Palette is summoned via the low-level global hotkey (UseLowLevelGlobalHotkey) by ensuring the summon handler runs on the UI thread rather than directly on the WH_KEYBOARD_LL hook callback thread (which is an input-synchronous context and can’t safely perform WinUI/COM window operations).
Changes:
- Wrapes the
KeyboardListenerProcessCommandcallback to enqueueHandleSummononto the windowDispatcherQueue. - Adds detailed inline documentation explaining the
RPC_E_CANTCALLOUT_ININPUTSYNCCALL (0x8001010D)failure mode and why dispatching resolves it.
Comment on lines
+146
to
147
| (id) => DispatcherQueue.TryEnqueue(() => HandleSummon(id)))); | ||
|
|
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.
Summary of the Pull Request
Fixes
RPC_E_CANTCALLOUT_ININPUTSYNCCALL(0x8001010D) crash when CmdPal is summoned via the low-level keyboard hook (UseLowLevelGlobalHotkey). TheWH_KEYBOARD_LLhook fires on an input-synchronous thread; callingHandleSummondirectly from it triggeredHideWindow()→ShowWindow→ WinUI COM calls, which COM forbids in that context.PR Checklist
Detailed Description of the Pull Request / Additional comments
MainWindow.xaml.cs—SetProcessCommandregistrationThe
ProcessCommanddelegate passed toKeyboardListenerwas a direct method reference, soHandleSummonran synchronously on the hook thread. Wrapping it withDispatcherQueue.TryEnqueueposts the work to the UI thread's message queue, ensuring it executes after the hook callback returns:The
WM_HOTKEYpath (HotKeyPrc) is unaffected — it already runs on the UI thread's message pump.Validation Steps Performed
MainWindow(e.g.SettingsChangedHandler,DragCompletedMessage) where off-thread callbacks are marshalled to the UI thread viaDispatcherQueue.TryEnqueue.