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

Support for win32-input-mode #1509

Closed
nico-abram opened this issue Jan 6, 2022 · 5 comments
Closed

Support for win32-input-mode #1509

nico-abram opened this issue Jan 6, 2022 · 5 comments
Labels
enhancement New feature or request keyboard Keyboard mapping/handling Windows Issue applies to Microsoft Windows

Comments

@nico-abram
Copy link
Contributor

As mentioned in #318 (comment) VT sequences cannot send everything that windows console programs expect (Encoded as win32 INPUT_RECORD's). That issue is about a very specific issue, so I'm opening this one to track support for the propietary win32-input-mode as described in https://github.com/microsoft/terminal/blob/main/doc/specs/%234999%20-%20Improved%20keyboard%20handling%20in%20Conpty.md

However, conpty's keyboard input is fundamentally backed by VT sequences, which limits the range of keys that a terminal application can actually send relative to what the console was capable of. This results in a number of keys that were previously representable in the console as INPUT_RECORDs, but are impossible to send to a client application that's running in conpty mode.

Like wez mentioned in this comment xtermjs/xterm.js#2357 may have some useful comments.

The specific issue I'm having that makes me interested in this is the "Modifier keys are not properly propagated to applications on windows" (documented well for WT here, and more specifically with far manager as mentioned here) listed in the document, but I imagine eventually users with all the problems mentioned in the abstract will show up.

Here are the alternatives I can think of:

  • Refuse to implement the mode and don't fully support win32 applications that make use of things not representable as VT
@nico-abram nico-abram added the enhancement New feature or request label Jan 6, 2022
@wez wez added the keyboard Keyboard mapping/handling label Jan 6, 2022
wez added a commit that referenced this issue Jan 6, 2022
…ut-mode

This is a baby step that formalizes the different encoding schemes into
an enum, and hooks up the decset sequence for win32-input-mode.

It doesn't change any of the actual encoding at this time.

refs: #1509
wez added a commit that referenced this issue Jan 6, 2022
wez added a commit that referenced this issue Jan 6, 2022
Nothing generates them right now, and the mux client has no
way to represent them on the wire.

I'm considering constraining them to just win32 for now.

refs: #1509
wez added a commit that referenced this issue Jan 6, 2022
wez added a commit that referenced this issue Jan 6, 2022
This commit causes the terminal to emit win32-input-mode encoded key up
and down events for a limited subset of keys When win32-input-mode is
enabled.

We limit them to keys where we know the VK key code equivalent,
and where those keys are either not representable (eg: modifier
only key events), or may generate ambiguous output (eg: CTRL-SPACE
in different keyboard layouts).

However, in my experiments, modifier only key presses confuse powershell
and cause it to emit `@`, so I've disabled that in the code for now.

refs: #318
refs: #1509
refs: #1510
wez added a commit that referenced this issue Jan 6, 2022
Normalize the left/right to the main VK.

Fixup the left/right control modifier flags: they were flipped!

refs: #318
refs: #1509
refs: #1510
@wez wez added the fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds. label Jan 6, 2022
@wez
Copy link
Owner

wez commented Jan 6, 2022

This is now implemented in the nightly, with restrictions: only for ambiguous or modifier only keys, which are the ones where this makes the most sense anyway.

@nico-abram
Copy link
Contributor Author

I can confirm holding modifier keys seems to work fine on nigthtly

wez added a commit that referenced this issue Jan 7, 2022
We need 100% of the info for it to work correctly, so this commit:

* Exposes the keyboard encoding mode via the Pane trait
* Adds the scan code to the RawKeyEvent
* Has the GUI perform the encoding if the keyboard is set that way
* Removes the basic encoder from termwiz in favor of the gui level one

The net result is that we bypass the Pane::key_up/Pane::key_down methods
in almost all cases when the encoding mode is set to win32-input-mode.

There is now a config option: allow_win32_input_mode that can be
used to prevent using this mode.

refs: #1509
@wez wez closed this as completed in 3ca840a Jan 8, 2022
@wez wez reopened this Jan 8, 2022
@wez
Copy link
Owner

wez commented Jan 8, 2022

@DHowett: first bug report about this is: with W32IM enabled in a cmd or pwsh, CTRL+key works correctly. If that session then runs wsl.exe the CTRL modifier is lost, so CTRL-C just sends C, CTRL-L is just L and so on.

This is what wezterm is sending in; the Encoded input as lines are what we write through to conpty:

key_event RawKeyEvent { key: Physical(C), modifiers: CTRL, phys_code: Some(C), raw_code: 67, scan_code: 46, repeat_count: 1, key_is_down: true, handled: Handled(false) }
key_event KeyEvent { key: Char('c'), modifiers: CTRL, repeat_count: 1, key_is_down: true, raw: Some(RawKeyEvent { key: Physical(C), modifiers: CTRL, phys_code: Some(C), raw_code: 67, scan_code: 46, repeat_count: 1, key_is_down: true, handled: Handled(false) }) }
send to pane key=Char('c') mods=CTRL
Encoded input as "\u{1b}[67;46;99;1;8;1_"
key_event RawKeyEvent { key: Physical(C), modifiers: CTRL, phys_code: Some(C), raw_code: 67, scan_code: 46, repeat_count: 1, key_is_down: false, handled: Handled(false) }
key_event KeyEvent { key: Char('c'), modifiers: CTRL, repeat_count: 1, key_is_down: false, raw: Some(RawKeyEvent { key: Physical(C), modifiers: CTRL, phys_code: Some(C), raw_code: 67, scan_code: 46, repeat_count: 1, key_is_down: false, handled: Handled(false) }) }
send to pane key=Char('c') mods=CTRL
Encoded input as "\u{1b}[67;46;99;0;8;1_"

@wez wez added the Windows Issue applies to Microsoft Windows label Jan 8, 2022
wez added a commit that referenced this issue Jan 8, 2022
Our last update was more than 6 months ago.

refs: #1509
wez added a commit that referenced this issue Jan 8, 2022
Until we can figure out why running wsl breaks CTRL modifiers!

refs: #1509
@wez
Copy link
Owner

wez commented Jan 8, 2022

@nico-abram heads up: I turned off allow_win32_input_mode by default until we can figure out what's happening with wsl. You can set allow_win32_input_mode=true in your config to get back your FAR manager modifiers :)

@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2023

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request keyboard Keyboard mapping/handling Windows Issue applies to Microsoft Windows
Projects
None yet
Development

No branches or pull requests

2 participants