dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.9k stars 4.63k forks source link

Support language input keys #63034

Open cm3 opened 2 years ago

cm3 commented 2 years ago

Language input keys are not defined in

That causes issues like https://github.com/PowerShell/PSReadLine/issues/2206.

So I recommend ConsoleKey to include:

Virtual-Key Codes (Winuser.h) - Win32 apps | Microsoft Docs lists up other language input keys, too. And, according to the entry in Windows Blog for Japan (Japanese), codes below also should be added.

ghost commented 2 years ago

Tagging subscribers to this area: @dotnet/area-system-console See info in area-owners.md if you want to be subscribed.

Issue Details
[Language input keys](https://en.wikipedia.org/wiki/Language_input_keys) are not defined in - https://github.com/dotnet/runtime/blob/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657/src/libraries/System.Console/src/System/ConsoleKey.cs - https://github.com/dotnet/runtime/blob/8048fe613933a1cd91e3fad6d571c74f726143ef/src/libraries/System.Console/ref/System.Console.cs That causes issues like https://github.com/PowerShell/PSReadLine/issues/2206. So I recommend ConsoleKey to include: - Convert / 28 / 0x1C - NonConvert / 29 / 0x1D [Virtual\-Key Codes \(Winuser\.h\) \- Win32 apps \| Microsoft Docs](https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes) lists up other language input keys, too. And, according to [the entry in Windows Blog for Japan](https://blogs.windows.com/japan/2021/05/10/windows-10-japanese-input-improvements/) (Japanese), codes below also should be added. - ImeOn / 22 / 0x16 - ImeOff / 26 / 0x1A
Author: cm3
Assignees: -
Labels: `area-System.Console`, `untriaged`
Milestone: -
huoyaoyuan commented 2 years ago

The following API is proposed:

namespace System
{
    enum ConsoleKey
    {
        Convert = 0x1C, // or named as ImeConvert
        NonConvert = 0x1D, // or named as ImeNonConvert
        ImeOn = 0x16,
        ImeOff = 0x1A,
    }
}
cm3 commented 2 years ago

Winforms use IMEConvert and IMENonconvert for the API names and the same names can be preferred. https://github.com/dotnet/winforms/blob/main/src/System.Windows.Forms/src/System/Windows/Forms/Keys.cs

danmoseley commented 2 years ago

In the public winforms enum linked I notice a typo: "IMEAceept"..

cm3 commented 2 years ago

@danmoseley That is for backward compatibility.

https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.keys?view=windowsdesktop-6.0&viewFallbackFrom=net-5.0 says "The IME accept key. Obsolete, use IMEAccept instead."

A comment in http://www.mikepope.com/blog/AddComment.aspx?blogid=2250 explains the history:

I found System.Windows.Forms.Keys.ImeAceept (ImeAccept) after we shipped it. After that, I put in a test for exposed interface on the windows forms stuff. Every time the interface changed, the test would fail, and I'd have to go look at it and make sure everything was cool. I filed over a dozen bugs on new spelling errors in the interface as a result of the test...

adamsitnik commented 2 years ago

For now I've added this issue to https://github.com/dotnet/runtime/issues/52374, will try to tackle it when we start working on improving Console

adamsitnik commented 9 months ago

Is it possible to recognize them on Unix?

cm3 commented 9 months ago

Are you making a distinction between Linux and Unix in your statement? If not, I am happy to report that those keys are recognised on Ubuntu. If so, please wait for another report from someone.

adamsitnik commented 9 months ago

I am happy to report that those keys are recognised on Ubuntu

Is there any chance you could run showkey -a command line utility and press that key to see what it's being mapped to?

I've used it in https://devblogs.microsoft.com/dotnet/console-readkey-improvements-in-net-7/#sys-calls

cm3 commented 5 months ago

I apologize for the significant delay in responding to your inquiry regarding the key recognition issue on Linux. After finally conducting the tests you suggested, I have some results to share. Unfortunately, the showkey -a command did not register any response for either of the keys in question. However, by using the xev command, I was able to determine that the Non Convert key is recognized as keycode 102 (keysym 0xff22, Muhenkan) and the Convert key as keycode 100 (keysym 0xff23, Henkan_Mode). The PC with Ubuntu installed, on which I intended to perform these tests, was no longer operational. In its place, I've found another PC running Peppermint Linux, which I used to conduct the tests and gather this report.