[PR #15130] [MERGED] Send a KeyUp sequence only once a key has been released #30442

Open
opened 2026-01-31 09:40:50 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/15130
Author: @j4james
Created: 4/6/2023
Status: Merged
Merged: 4/11/2023
Merged by: @DHowett

Base: mainHead: fix-keyup-events


📝 Commits (1)

  • 5da29bd Send KeyUp events only when keys are released.

📊 Changes

1 file changed (+5 additions, -12 deletions)

View changed files

📝 src/cascadia/TerminalCore/Terminal.cpp (+5 -12)

📄 Description

When win32-input-mode is enabled, we generate an input sequence for both
key down and key up events. However, in the initial implementation the
key up sequence for most keypresses would be faked - they were generated
at the same time as the key down sequence, regardless of when the key
was actually released. After this PR, we'll only generate the key up
sequence once a key has actually been released.

References and Relevant Issues

The initial implementation of win32-input-mode was in PR #6309.
The spec for win32-input-mode was in PR #5887.

Validation Steps Performed

I've manually tested this with an app that polls ReadConsoleInput in a
loop and logs the results. With this PR applied, I can now see the key
up events as a key is released, rather than when it was first pressed.

When compared with conhost, though, there are some differences. When
typing a shifted key, e.g. Shift+A, WT generates key down and key up
events for both the Shift and the A, while conhost only generates
both events for the Shift - the A won't generate a key up event
unless you release the Shift before the A. That seems more like a
conhost flaw though.

Another case I tested was the Japanese Microsoft IME, which in conhost
will generate a key down event for the Japanese character being inserted
followed by a key up event for for Return. WT generates key up events
for the ASCII characters being typed in the IME, then both a key down
and key up event for the inserted Japanese character, and finally a key
up event for Return. Both of those seem weird, but they still appear
to work OK.

The current version of WT actually produces the most sensible behavior
for the IME - it just generates key up and key down events for the
inserted character. But that's only because it's dropping most of the
system generated key up events.

Closes #8440


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/15130 **Author:** [@j4james](https://github.com/j4james) **Created:** 4/6/2023 **Status:** ✅ Merged **Merged:** 4/11/2023 **Merged by:** [@DHowett](https://github.com/DHowett) **Base:** `main` ← **Head:** `fix-keyup-events` --- ### 📝 Commits (1) - [`5da29bd`](https://github.com/microsoft/terminal/commit/5da29bdda01e5d99afa32ed78514fb0e4497a9e0) Send KeyUp events only when keys are released. ### 📊 Changes **1 file changed** (+5 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalCore/Terminal.cpp` (+5 -12) </details> ### 📄 Description When win32-input-mode is enabled, we generate an input sequence for both key down and key up events. However, in the initial implementation the key up sequence for most keypresses would be faked - they were generated at the same time as the key down sequence, regardless of when the key was actually released. After this PR, we'll only generate the key up sequence once a key has actually been released. ## References and Relevant Issues The initial implementation of win32-input-mode was in PR #6309. The spec for win32-input-mode was in PR #5887. ## Validation Steps Performed I've manually tested this with an app that polls `ReadConsoleInput` in a loop and logs the results. With this PR applied, I can now see the key up events as a key is released, rather than when it was first pressed. When compared with conhost, though, there are some differences. When typing a shifted key, e.g. `Shift`+`A`, WT generates key down and key up events for both the `Shift` and the `A`, while conhost only generates both events for the `Shift` - the `A` won't generate a key up event unless you release the `Shift` before the `A`. That seems more like a conhost flaw though. Another case I tested was the Japanese Microsoft IME, which in conhost will generate a key down event for the Japanese character being inserted followed by a key up event for for `Return`. WT generates key up events for the ASCII characters being typed in the IME, then both a key down and key up event for the inserted Japanese character, and finally a key up event for `Return`. Both of those seem weird, but they still appear to work OK. The current version of WT actually produces the most sensible behavior for the IME - it just generates key up and key down events for the inserted character. But that's only because it's dropping most of the system generated key up events. Closes #8440 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:40:50 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#30442