## Summary Fixes #48274 When previewing a file with Peek, clicking inside the preview content (PDF, text/code, markdown, HTML) makes **Ctrl+W unable to close the window**. This happens because the preview controls (WebView2 for most file types, native shell handlers for others) capture keyboard focus in their own message loop, bypassing the XAML keyboard accelerator system entirely. ## Problem Peek defines keyboard shortcuts (Ctrl+W to close, Escape to close, arrow keys to navigate) as `KeyboardAccelerator` elements on the main XAML Grid. These only fire when keyboard input flows through the XAML input system. However: - **WebView2** (used for PDF, text/code via Monaco, markdown, HTML): Runs Chromium in a separate process that consumes all keyboard input when focused. Ctrl+W is particularly problematic because Chromium treats it as "close tab." - **Shell Preview Handlers** (native HWND): Run in a child Win32 window that handles keyboard messages independently. Once either of these controls gets focus via a mouse click, keyboard shortcuts stop working. ## Solution Added a **low-level keyboard hook** (`WH_KEYBOARD_LL`) that intercepts key events at the OS level, regardless of which control has focus: - **Ctrl+W** and **Escape** → close the Peek window - **Arrow keys** (Left/Right/Up/Down without Ctrl) → navigate between files The hook is installed only while the Peek window is visible and only acts when Peek is the foreground window, so it has no impact on other applications. As additional defense-in-depth, `AreBrowserAcceleratorKeysEnabled` is set to `false` on the WebView2 control, preventing Chromium from consuming browser-specific shortcuts like Ctrl+W. ## Changes | File | Change | |------|--------| | `Peek.UI/PeekXAML/MainWindow.xaml.cs` | Install/uninstall keyboard hook in Initialize/Uninitialize; hook callback handles Ctrl+W, Escape, and arrow keys | | `Peek.UI/Native/NativeMethods.cs` | P/Invoke declarations for `SetWindowsHookEx`, `UnhookWindowsHookEx`, `CallNextHookEx`, `GetAsyncKeyState` | | `Peek.FilePreviewer/Controls/BrowserControl.xaml.cs` | Disable browser accelerator keys on WebView2 | ## Validation - [x] Ctrl+W closes Peek after clicking inside PDF preview - [x] Ctrl+W closes Peek after clicking inside text/code preview (Monaco) - [x] Escape closes Peek after clicking inside preview - [x] Arrow keys navigate between files after clicking inside preview - [x] Normal typing/interaction inside previews still works (Ctrl+C, scrolling, etc.) - [x] Shortcuts still work without clicking (existing behavior preserved) --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Microsoft PowerToys
Microsoft PowerToys is a collection of utilities that help you customize Windows and streamline everyday tasks.
Installation · Documentation · Blog · Release notes
🔨 Utilities
PowerToys includes over 30 utilities to help you customize and optimize your Windows experience:
📦 Installation
For detailed installation instructions and system requirements, visit the installation docs.
But to get started quickly, choose one of the installation methods below:
Download the .exe file from GitHub
Go to the PowerToys GitHub releases, scroll down and select Assets to reveal the installation files, and choose the one that matches your architecture and install scope. For most devices, that would be x64 per-user.
WinGet
Download PowerToys from [WinGet](https://github.com/microsoft/winget-cli#installing-the-client). Updating PowerToys via winget will respect the current PowerToys installation scope. To install PowerToys, run the following command from the command line / PowerShell:
- User scope installer (default)
winget install Microsoft.PowerToys -s winget
- Machine-wide scope installer
winget install --scope machine Microsoft.PowerToys -s winget
Other methods
There are [community driven install methods](https://learn.microsoft.com/windows/powertoys/install#community-driven-install-tools) such as Chocolatey and Scoop. If these are your preferred install solutions, you can find the install instructions there.
✨ What's new?
To see what's new, check out the release notes.
🛣️ Roadmap
We are planning some nice new features and improvements for the next releases – a brand-new Shortcut Guide experience, ensuring it's easier to find and install Command Palette extensions and so much more! Stay tuned for v0.100!
❤️ PowerToys Community
The PowerToys team is extremely grateful to have the support of an amazing active community. The work you do is incredibly important. PowerToys wouldn't be nearly what it is today without your help filing bugs, updating documentation, guiding the design, or writing features. We want to say thank you and take time to recognize your work. Your contributions and feedback improve PowerToys month after month!
Contributing
This project welcomes contributions of all types. Besides coding features / bug fixes, other ways to assist include spec writing, design, documentation, and finding bugs. We are excited to work with the power user community to build a set of tools for helping you get the most out of Windows. We ask that before you start work on a feature that you would like to contribute, please read our Contributor's Guide. We would be happy to work with you to figure out the best approach, provide guidance and mentorship throughout feature development, and help avoid any wasted or duplicate effort. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you grant us the rights to use your contribution and that you have permission to do so. For guidance on developing for PowerToys, please read the developer docs for a detailed breakdown. This includes how to setup your computer to compile.
Code of conduct
This project has adopted the Microsoft Open Source Code of Conduct.
Privacy statement
The application logs basic diagnostic data (telemetry). For more privacy information and what we collect, see our PowerToys Data and Privacy documentation.

