ConPTY doesn't set KeyEvent::_virtualScanCode for certain characters like : (which bothers GoW less) #4013

Closed
opened 2026-01-30 23:35:49 +00:00 by claunia · 20 comments
Owner

Originally created by @perlmaster on GitHub (Sep 24, 2019).

Environment

Windows 10
Any other software?


# Steps to reproduce

1. Run cmd.exe under windows terminal preview
2. navigate to a directory containing text files
3. Run the command "less -MN *.txt"
4. When you reach the end of the 1st file enter the "less" command ":n" to go to the next file

# Expected behavior
"less" should start displaying the next file.

# Actual behavior
I get the following error message "no previous regular expression". This does not happen when I run less under a cmd.exe session the old fashioned way.
Originally created by @perlmaster on GitHub (Sep 24, 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! --> <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. If this is an application crash, please also provide a Feedback Hub submission link so we can find your diagnostic data on the backend. Use the category "Apps > Windows Terminal (Preview)" and choose "Share My Feedback" after submission to get the link. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment Windows 10 Any other software? ``` # Steps to reproduce 1. Run cmd.exe under windows terminal preview 2. navigate to a directory containing text files 3. Run the command "less -MN *.txt" 4. When you reach the end of the 1st file enter the "less" command ":n" to go to the next file # Expected behavior "less" should start displaying the next file. # Actual behavior I get the following error message "no previous regular expression". This does not happen when I run less under a cmd.exe session the old fashioned way.
Author
Owner

@DHowett-MSFT commented on GitHub (Sep 24, 2019):

less doesn't ship with Windows, so you're going to need to share exactly which less you are using. Otherwise, we can't exactly debug the issue.

@DHowett-MSFT commented on GitHub (Sep 24, 2019): `less` doesn't ship with Windows, so you're going to need to share exactly _which `less` you are using_. Otherwise, we can't exactly debug the issue.
Author
Owner

@perlmaster commented on GitHub (Sep 24, 2019):

according to "less --version" I am running less version 378

@perlmaster commented on GitHub (Sep 24, 2019): according to "less --version" I am running less version 378
Author
Owner

@zadjii-msft commented on GitHub (Sep 24, 2019):

I think @DHowett-MSFT meant more of "are you using wsl's less, cygwin's less, some unknown less.exe?"

@zadjii-msft commented on GitHub (Sep 24, 2019): I think @DHowett-MSFT meant more of "are you using wsl's `less`, cygwin's `less`, some unknown `less.exe`?"
Author
Owner

@perlmaster commented on GitHub (Sep 24, 2019):

I downloaded "less" a long time ago. I don't remember exactly where I got it.

The command "less --version" produces the following

less 378
Copyright (C) 2002 Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Homepage: http://www.greenwoodsoftware.com/less

In the documentation I got at the time, there is the following paragraph:

   Copyright (C) 2002  Mark Nudelman

   less is part of the GNU project and is free software.  You
   can redistribute it and/or modify it under  the  terms  of
   either  (1) the GNU General Public License as published by
   the Free Software Foundation; or  (2)  the  Less  License.

Although I have cygwin, I do not use it.

@perlmaster commented on GitHub (Sep 24, 2019): I downloaded "less" a long time ago. I don't remember exactly where I got it. The command "less --version" produces the following less 378 Copyright (C) 2002 Mark Nudelman less comes with NO WARRANTY, to the extent permitted by law. For information about the terms of redistribution, see the file named README in the less distribution. Homepage: http://www.greenwoodsoftware.com/less In the documentation I got at the time, there is the following paragraph: Copyright (C) 2002 Mark Nudelman less is part of the GNU project and is free software. You can redistribute it and/or modify it under the terms of either (1) the GNU General Public License as published by the Free Software Foundation; or (2) the Less License. Although I have cygwin, I do not use it.
Author
Owner

@zadjii-msft commented on GitHub (Sep 26, 2019):

So the less I have on WSL is just about 100 versions more updated - could you maybe try a newer less version?

zadjii@migrie-slaptop:~$ less --version
less 487 (GNU regular expressions)
Copyright (C) 1984-2016  Mark Nudelman

I can only find posts about sed creating that "no previous regular expression" error, so I'm not really sure how that's getting into less, or how the terminal might be feeding bad characters into it.

What keyboard layout are you using?

@zadjii-msft commented on GitHub (Sep 26, 2019): So the less I have on WSL is just about 100 versions more updated - could you maybe try a newer `less` version? ``` zadjii@migrie-slaptop:~$ less --version less 487 (GNU regular expressions) Copyright (C) 1984-2016 Mark Nudelman ``` I can only find posts about `sed` creating that "no previous regular expression" error, so I'm not really sure how that's getting into less, or how the terminal might be feeding bad characters into it. What keyboard layout are you using?
Author
Owner

@perlmaster commented on GitHub (Sep 26, 2019):

I must be having a slow day. Who or what is WSL ?

@perlmaster commented on GitHub (Sep 26, 2019): I must be having a slow day. Who or what is WSL ?
Author
Owner

@perlmaster commented on GitHub (Sep 26, 2019):

Sorry, it just occured to me that WSL == Windows Subsystem for Linux

@perlmaster commented on GitHub (Sep 26, 2019): Sorry, it just occured to me that WSL == Windows Subsystem for Linux
Author
Owner

@perlmaster commented on GitHub (Sep 26, 2019):

Does anyone know where I can find a compiled binary version of less ? So far the only thing I have found is source code and I have always had issues trying to compile anything that requires the bourne shell to run a script named "configure" which starts the whole build process. On my windows 10 64 bit system I can't get sh.exe to run properly

@perlmaster commented on GitHub (Sep 26, 2019): Does anyone know where I can find a compiled binary version of less ? So far the only thing I have found is source code and I have always had issues trying to compile anything that requires the bourne shell to run a script named "configure" which starts the whole build process. On my windows 10 64 bit system I can't get sh.exe to run properly
Author
Owner

@DHowett-MSFT commented on GitHub (Oct 8, 2019):

That's a really good question, honestly. It looks like the GoW project produces binaries of these tools with reasonable frequency, but their terminal emulator bridge leaves a little bit to be desired. Perhaps their less works slightly better than the one you've got?

Sorry, I know it's not much. 😄

@DHowett-MSFT commented on GitHub (Oct 8, 2019): That's a really good question, honestly. It looks like the _GoW_ project produces binaries of these tools with reasonable frequency, but their terminal emulator bridge leaves a little bit to be desired. Perhaps their `less` works slightly better than the one you've got? Sorry, I know it's not much. :smile:
Author
Owner

@ghost commented on GitHub (Oct 12, 2019):

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@ghost commented on GitHub (Oct 12, 2019): This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for **4 days**. It will be closed if no further activity occurs **within 3 days of this comment**.
Author
Owner

@perlmaster commented on GitHub (Oct 12, 2019):

The GoW version of less did not solve the problem. I am continuing my search for some kind of solution.

@perlmaster commented on GitHub (Oct 12, 2019): The GoW version of less did not solve the problem. I am continuing my search for some kind of solution.
Author
Owner

@DHowett-MSFT commented on GitHub (Oct 12, 2019):

That is very good news for us, because now we have learned of a distribution of less that we can use for a repro. Thank you!

What keyboard layout are you using? Standard en-US PC104?

@DHowett-MSFT commented on GitHub (Oct 12, 2019): That is very good news for us, because now we have learned of a distribution of less that we can use for a repro. Thank you! What keyboard layout are you using? Standard en-US PC104?
Author
Owner

@perlmaster commented on GitHub (Oct 12, 2019):

I am not sure about the exact specs for my keyboard, but it is definitely en-US. I am unable to determine if it is PC104 , I have checked in the control panels and nothing speaks of PC104

@perlmaster commented on GitHub (Oct 12, 2019): I am not sure about the exact specs for my keyboard, but it is definitely en-US. I am unable to determine if it is PC104 , I have checked in the control panels and nothing speaks of PC104
Author
Owner

@perlmaster commented on GitHub (Oct 12, 2019):

just for the record I have the same issue wether I use my laptop keyboard or my wired USB keyboard

@perlmaster commented on GitHub (Oct 12, 2019): just for the record I have the same issue wether I use my laptop keyboard or my wired USB keyboard
Author
Owner

@0xd4d commented on GitHub (Oct 12, 2019):

Try less that's part of Git for Windows

@0xd4d commented on GitHub (Oct 12, 2019): Try `less` that's part of [Git for Windows](https://git-scm.com/download/win)
Author
Owner

@perlmaster commented on GitHub (Oct 12, 2019):

I already had git for windows 2.15.0 on my system. I was not aware that it had all those extra executables. It had less version 481. That version of less seems to be working just fine !

That solves my specific issue. Thanks to all who helped !

@perlmaster commented on GitHub (Oct 12, 2019): I already had git for windows 2.15.0 on my system. I was not aware that it had all those extra executables. It had less version 481. That version of less seems to be working just fine ! That solves my specific issue. Thanks to all who helped !
Author
Owner

@DHowett-MSFT commented on GitHub (Oct 12, 2019):

And we've got a root cause, too!

It looks like some versions of less for windows are checking the scancode of the keyboard key that's pressed, and when that key comes in off a pty (which Windows Terminal, VSCode, Visual Studio, etc. use), that scancode isn't set.

pseudoconsole

↓ wch:0 '\0' mod:Shift (16) repeat:1 vk:16 vsc:42
↓ wch:0 '\0' mod:Shift (16) repeat:1 vk:16 vsc:42
↓ wch:58 ':' mod:Shift (16) repeat:1 vk:186 vsc:0 <--- bad (0)
↓ wch:58 ':' mod:Shift (16) repeat:1 vk:186 vsc:0 <---
↑ wch:58 ':' mod:Shift (16) repeat:1 vk:186 vsc:0 <---
↑ wch:58 ':' mod:Shift (16) repeat:1 vk:186 vsc:0 <---
↑ wch:0 '\0' mod:None (0) repeat:1 vk:16 vsc:42
↑ wch:0 '\0' mod:None (0) repeat:1 vk:16 vsc:42

conhost

↓ wch:0 '\0' mod:Shift (16) repeat:1 vk:16 vsc:42
↓ wch:0 '\0' mod:Shift (16) repeat:1 vk:16 vsc:42
↓ wch:58 ':' mod:Shift (16) repeat:1 vk:186 vsc:39 <--- good (39)
↓ wch:58 ':' mod:Shift (16) repeat:1 vk:186 vsc:39 <--- good (39)
↑ wch:0 '\0' mod:None (0) repeat:1 vk:16 vsc:42
↑ wch:0 '\0' mod:None (0) repeat:1 vk:16 vsc:42
@DHowett-MSFT commented on GitHub (Oct 12, 2019): And we've got a root cause, too! It looks like some versions of less for windows are checking the _scancode_ of the keyboard key that's pressed, and when that key comes in off a pty (which Windows Terminal, VSCode, Visual Studio, etc. use), _that scancode isn't set._ ### pseudoconsole ``` ↓ wch:0 '\0' mod:Shift (16) repeat:1 vk:16 vsc:42 ↓ wch:0 '\0' mod:Shift (16) repeat:1 vk:16 vsc:42 ↓ wch:58 ':' mod:Shift (16) repeat:1 vk:186 vsc:0 <--- bad (0) ↓ wch:58 ':' mod:Shift (16) repeat:1 vk:186 vsc:0 <--- ↑ wch:58 ':' mod:Shift (16) repeat:1 vk:186 vsc:0 <--- ↑ wch:58 ':' mod:Shift (16) repeat:1 vk:186 vsc:0 <--- ↑ wch:0 '\0' mod:None (0) repeat:1 vk:16 vsc:42 ↑ wch:0 '\0' mod:None (0) repeat:1 vk:16 vsc:42 ``` ### conhost ``` ↓ wch:0 '\0' mod:Shift (16) repeat:1 vk:16 vsc:42 ↓ wch:0 '\0' mod:Shift (16) repeat:1 vk:16 vsc:42 ↓ wch:58 ':' mod:Shift (16) repeat:1 vk:186 vsc:39 <--- good (39) ↓ wch:58 ':' mod:Shift (16) repeat:1 vk:186 vsc:39 <--- good (39) ↑ wch:0 '\0' mod:None (0) repeat:1 vk:16 vsc:42 ↑ wch:0 '\0' mod:None (0) repeat:1 vk:16 vsc:42 ```
Author
Owner

@DHowett-MSFT commented on GitHub (Oct 12, 2019):

And as a final followup, it's because somewhere deep in the console host, we're doing a "vkey to vsc" translation, but we're providing it a character instead of a vkey. 🤦‍♂

@DHowett-MSFT commented on GitHub (Oct 12, 2019): And as a final followup, it's because somewhere deep in the console host, we're doing a "vkey to vsc" translation, but we're providing it a character instead of a vkey. 🤦‍♂
Author
Owner

@DHowett-MSFT commented on GitHub (Oct 12, 2019):

diff --git a/src/types/convert.cpp b/src/types/convert.cpp
index c2049ded9..bc87bab18 100644
--- a/src/types/convert.cpp
+++ b/src/types/convert.cpp
@@ -206,7 +206,8 @@ std::deque<std::unique_ptr<KeyEvent>> SynthesizeKeyboardEvents(const wchar_t wch
                                                        SHIFT_PRESSED));
     }

-    const WORD virtualScanCode = gsl::narrow<WORD>(MapVirtualKeyW(wch, MAPVK_VK_TO_VSC));
+    auto vk = keyState & 0xFF;
+    const WORD virtualScanCode = gsl::narrow<WORD>(MapVirtualKeyW(vk, MAPVK_VK_TO_VSC));
     KeyEvent keyEvent{ true, 1, LOBYTE(keyState), virtualScanCode, wch, 0 };

     // add modifier flags if necessary
@DHowett-MSFT commented on GitHub (Oct 12, 2019): ```diff diff --git a/src/types/convert.cpp b/src/types/convert.cpp index c2049ded9..bc87bab18 100644 --- a/src/types/convert.cpp +++ b/src/types/convert.cpp @@ -206,7 +206,8 @@ std::deque<std::unique_ptr<KeyEvent>> SynthesizeKeyboardEvents(const wchar_t wch SHIFT_PRESSED)); } - const WORD virtualScanCode = gsl::narrow<WORD>(MapVirtualKeyW(wch, MAPVK_VK_TO_VSC)); + auto vk = keyState & 0xFF; + const WORD virtualScanCode = gsl::narrow<WORD>(MapVirtualKeyW(vk, MAPVK_VK_TO_VSC)); KeyEvent keyEvent{ true, 1, LOBYTE(keyState), virtualScanCode, wch, 0 }; // add modifier flags if necessary ```
Author
Owner

@ghost commented on GitHub (Oct 23, 2019):

:tada:This issue was addressed in #3199, which has now been successfully released as Windows Terminal Preview v0.6.2951.0.🎉

Handy links:

@ghost commented on GitHub (Oct 23, 2019): :tada:This issue was addressed in #3199, which has now been successfully released as `Windows Terminal Preview v0.6.2951.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v0.6.2951.0) * [Store Download](https://www.microsoft.com/store/apps/9n0dx20hk701?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#4013