Skip to content

Incorrect keycode for "CTRL+H" in Windows Terminal #5957

@skywind3000

Description

@skywind3000

Environment

Windows: 
Platform ServicePack Version      VersionString
-------- ----------- -------      -------------
 Win32NT             10.0.18363.0 Microsoft Windows NT 10.0.18363.0

Vim.exe: 8.2.701

Steps to reproduce

  1. start "cmd.exe" in windows terminal.
  2. run vim.exe (https://github.com/vim/vim-win32-installer/releases)
  3. input "iaaaaaaa" to enter insert mode and append some characters.
  4. press "CTRL+h" several times

Expected behavior

The previous "aaaaa" should get deleted (CTRL+H in vim's insert mode will delete previous character), just like running vim.exe in the traditional cmd.exe window.

Actual behavior

图片

"CTRL+h" inserts some strange characters: "ÎzÎzÎzÎzÎzÎzÎz"

after some inspection, I located the difference, if I use getch in msvcrt.dll to display keycode:

  1. Run cmd.exe directly:
D:\>python -c "import msvcrt;print(msvcrt.getch())"
b'\x08'                   <--- press CTRL+H

D:\>python -c "import msvcrt;print(msvcrt.getch())"
b'\x08'                   <--- press BackSpace

Both "CTRL+H" and "BackSpace" are b'\x08', vim.exe works fine with it .

  1. Run cmd.exe in Windows Terminal:
D:\>python -c "import msvcrt;print(msvcrt.getch())"
b'\x7f'                   <--- press CTRL+H

D:\>python -c "import msvcrt;print(msvcrt.getch())"
b'\x08'                   <--- press BackSpace

Now, "CTRL+H" becomes b'\x7f' in Windows Terminal, which is different from running cmd.exe directly without windows terminal, and that difference breaks some terminal softwares like vim.exe .

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-InputRelated to input processing (key presses, mouse, etc.)Issue-BugIt either shouldn't be doing this or needs an investigation.Needs-Tag-FixDoesn't match tag requirementsPriority-2A description (P2)Product-ConptyFor console issues specifically related to conpty

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions