Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alt doesn't work for most of the non-alphabetic ASCII control characters (Alt-Ctrl-[, Alt-Ctrl-\, Alt-Ctrl-], Alt-Ctrl-^) #15367

Closed
aimfiz opened this issue May 16, 2023 · 4 comments · Fixed by #16511
Labels
Area-Input Related to input processing (key presses, mouse, etc.) Area-VT Virtual Terminal sequence support In-PR This issue has a related PR Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Tag-Fix Doesn't match tag requirements Product-Conhost For issues in the Console codebase
Milestone

Comments

@aimfiz
Copy link

aimfiz commented May 16, 2023

Windows Terminal version

1.16.10262.0

Windows build number

10.0.22621

Other Software

No response

Steps to reproduce

wsl
showkey -a

[type Ctrl-A, Alt-Ctrl-A, Ctrl-], Alt-Ctrl-], Ctrl-6, Alt-Ctrl-6]

Expected Behavior

^A        1 0001 0x01
^[^A     27 0033 0x1b
          1 0001 0x01
^]       29 0035 0x1d
^[^]     27 0033 0x1b
         29 0035 0x1d
^^       30 0036 0x1e
^[^^     27 0033 0x1b
         30 0036 0x1e

Generally, for any key press that produces the character code C in the range 0 through 127, the same key press but with the Alt key down should produce the character code 27 (i.e., escape) followed by the character code C. (Unless, of course, there is a conflicting, explicit binding. There's a default binding for Alt-Ctrl-6, but removing it doesn't help.)

Actual Behavior

^A        1 0001 0x01
^[^A     27 0033 0x1b
          1 0001 0x01
^]       29 0035 0x1d
^^       30 0036 0x1e
@aimfiz aimfiz added Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels May 16, 2023
@aimfiz
Copy link
Author

aimfiz commented May 16, 2023

The handling of un-Alt-ed control keys for the seven ASCII non-alphabetic control codes (0, 27-31, and 127) works fine, but the addition of Alt is broken for most of them. Specifically, I'm seeing:

key:    Ctrl-key generates:     Alt-Ctrl-key generates:
`~      0                       nothing
space   0                       27 0
2@      0                       27 0
3#      27                      nothing
4$      28                      nothing
5%      29                      nothing
6^      30                      nothing
7&      31                      nothing
8*      127                     nothing
[{      27                      nothing
\|      28                      nothing
]}      29                      nothing
/?      31                      27 31
backsp 127                      27 127

The problem seems to be in TerminalInput::HandleKey in src/terminal/input/terminalInput.cpp

@aimfiz
Copy link
Author

aimfiz commented May 17, 2023

A related issue is that control-minus should generate code 31, not 13.

In other words, because there is no ASCII control-minus, it's helpful and expected that one can type control-underscore using only the control key and the key with an underscore on it, without having to press shift as well. But it is unhelpful and not expected by anyone that pressing control-minus will generate control-M a/k/a carriage-return.

(By the same logic, control-slash (i.e., control-? without a shift) should produce 127, not 31 (i.e., control-?, not control-underscore). But that illogical binding has a few decades of precedent in xterm, so people do expect it.)

@carlos-zamora carlos-zamora added Product-Conhost For issues in the Console codebase Area-VT Virtual Terminal sequence support labels May 17, 2023
@carlos-zamora carlos-zamora added this to the Backlog milestone May 17, 2023
@carlos-zamora carlos-zamora removed the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label May 17, 2023
@carlos-zamora
Copy link
Member

Thanks for filing this! Surprised we haven't heard of this one before!

@aimfiz
Copy link
Author

aimfiz commented May 21, 2023

This issue is the more general case of issue #12555 (ctrl-alt-\ is ignored in WSL). As pointed out there, you can work around the problem by explicitly specifying a sendInput action for each key combination that doesn't work, e.g.:

        {
            "command": 
            {
                "action": "sendInput",
                "input": "\u001b\u001c"
            },
            "keys": "ctrl+alt+\\"
        },

@microsoft-github-policy-service microsoft-github-policy-service bot added the In-PR This issue has a related PR label Dec 31, 2023
@j4james j4james added the Area-Input Related to input processing (key presses, mouse, etc.) label Jan 2, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Tag-Fix Doesn't match tag requirements label Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Input Related to input processing (key presses, mouse, etc.) Area-VT Virtual Terminal sequence support In-PR This issue has a related PR Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Tag-Fix Doesn't match tag requirements Product-Conhost For issues in the Console codebase
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants