TermControl key down handling investigation and refactoring #5652

Open
opened 2026-01-31 00:18:20 +00:00 by claunia · 2 comments
Owner

Originally created by @KaiyuWang16 on GitHub (Dec 21, 2019).

In current TermControl implementation, KeyDown events are handled by PreviewKeyDown event. It uses Tunneling strategy and key down events will first be sent to XAML root element, which is TermControl.

SearchBoxControl is a child element of TermControl. Thus, key input events on SearchBoxControl will be sent to TermControl first. Now there is an early return check in TermControl::_KeyDownHandler, which prevents key inputs from Search Box to be processed by TermControl. But this is not a good implementation.

We need to think about using KeyDown instead of PreviewKeyDown event handler in TermControl, but we need to make sure this change won't break anything.

Originally created by @KaiyuWang16 on GitHub (Dec 21, 2019). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> In current TermControl implementation, KeyDown events are handled by PreviewKeyDown event. It uses Tunneling strategy and key down events will first be sent to XAML root element, which is TermControl. SearchBoxControl is a child element of TermControl. Thus, key input events on SearchBoxControl will be sent to TermControl first. Now there is an early return check in TermControl::_KeyDownHandler, which prevents key inputs from Search Box to be processed by TermControl. But this is not a good implementation. We need to think about using KeyDown instead of PreviewKeyDown event handler in TermControl, but we need to make sure this change won't break anything.
claunia added the Issue-TaskProduct-TerminalArea-TerminalControl labels 2026-01-31 00:18:20 +00:00
Author
Owner

@KaiyuWang16 commented on GitHub (Jan 7, 2020):

For now, there is a potential bug in TextBox: If e.handled is set to true in the KeyDown event handler for key inputs on TextBox, or even on the parent of TextBox, the input text won’t show up. This is might be a bug in TextBox in XAMLIsland. With this, checking whether the input comes from the SearchBoxControl is still necessary in TermControl::_KeyDownHandler. Thus, there is no obvious upside if we change PreviewKeyDown to KeyDown. I suggest leave it as it is and close this issue.

@KaiyuWang16 commented on GitHub (Jan 7, 2020): For now, there is a potential bug in TextBox: If e.handled is set to true in the KeyDown event handler for key inputs on TextBox, or even on the parent of TextBox, the input text won’t show up. This is might be a bug in TextBox in XAMLIsland. With this, checking whether the input comes from the SearchBoxControl is still necessary in TermControl::_KeyDownHandler. Thus, there is no obvious upside if we change PreviewKeyDown to KeyDown. I suggest leave it as it is and close this issue.
Author
Owner

@DHowett-MSFT commented on GitHub (Feb 26, 2020):

Potential direction: if we put the keyboard handler on the swapchain itself, like the mouse handler, we may not need tunneling any longer.

@DHowett-MSFT commented on GitHub (Feb 26, 2020): Potential direction: if we put the keyboard handler on the swapchain itself, _like the mouse handler_, we may not need tunneling any longer.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#5652