How to handle HotKey in WinUI3 window

Harshithraj1871 1,681 Reputation points
2025-03-11T12:45:28.5+00:00

Hi,

I'm working on a WinUI 3 desktop application in C++. I need to capture the CTRL + I shortcut in a WinUI 3 window. Since WinUI 3 does not support KeyboardAccelerators for windows, I tried using WM_HOTKEY. However, when a TextBox has focus and uses the same shortcut (CTRL +I), the hotkey is not triggered for the TextBox but is still captured at the window level. How can I ensure proper handling of CTRL + I without overriding TextBox behavior?

What is the best way to handle a HOTKEY in window level

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
838 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jeanine Zhang-MSFT 11,181 Reputation points Microsoft External Staff
    2025-03-12T03:40:17.06+00:00

    Hi

    Welcome to Microsoft Q&A!

    Currently, WinUI3 does not support KeyboardAccelerators for Windows. And someone has already submitted a feature request, refer to the GitHub: https://github.com/microsoft/microsoft-ui-xaml/issues/6467

    You could try to create a page under the windows and then using KeyboardAccelerators on the page to capture the Hotkey.

    How can I ensure proper handling of CTRL + I without overriding TextBox behavior?

    You couldn't do that. If the textbox has focus, then its CTRL +I event will always fire before the page. The reason is that the textbox is one layer above the page, and events are routed from the top layer to the bottom layer.

    Thank you

    Jeanine


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.