Chrome 远程桌面 Console.ReadKey 输出 System.ConsoleKey.Packet 而不是击键
Chrome remote desktop Console.ReadKey yelds System.ConsoleKey.Packet instead of keystroke
老实说,这更像是一种好奇心。
在我正在开发的控制台项目中,我以循环形式请求用户输入:
ConsoleKey response;
Console.Write("Write messages to log? [y/n] ");
response = Console.ReadKey(false).Key;
assume 4 cases:
case 1: Pressing the 'y' key on a keyboard directly atached to the pc running the software.
case 2: Connecting from another computer trough remote desktop connection and pressing the 'y' key on that machine.
case 3: Using on screen keyboard and press the 'y' key trough clicking on it (remotely or locally had no difference)
case 4: Connecting from another machine (specifically a phone) trough chrome remote desktop and pressing the 'y' key.
在情况 1、2 和 3 中,'response' 将包含 'Y'。
如果情况 4 'response' 将包含 System.ConsoleKey.Packet aka 枚举 231 PACKET 键(用于通过击键传递 Unicode 字符)。
我在第二台电脑上尝试了同样的事情,我注意到这种行为似乎没有发生。
最有趣的是控制台向我显示了这个
Write messages to log? [y/n] y
由此我证明确实收到了击键,但我的代码处理不正确。
我不知道如何继续。
Console.ReadLine 会产生正确的击键,但如果可能的话我更愿意使用 Console.ReadKey。
这是 phone 键盘的特定行为吗?我如何获得实际密钥?
How would I obtain the actual key?
MSDN docs for ConsoleKey.Packet
doesn't say anything useful, so I found references to ConsoleKey
in the source which lead here. That's casting ir.keyEvent.virtualKeyCode
to a ConsoleKey
where ir
is an InputRecord
.
快速 google 发现 WinApi 等效项是 INPUT_RECORD
, and chasing the docs through KEY_EVENT_RECORD
leads to this doc of Virtual-Key codes,其中包含 VK_PACKET
的更多文档:
Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP
INPUT_KEYBOARD supports nonkeyboard-input methods—such as handwriting recognition or voice recognition—as if it were text input by using the KEYEVENTF_UNICODE flag. If KEYEVENTF_UNICODE is specified, SendInput sends a WM_KEYDOWN or WM_KEYUP message to the foreground thread's message queue with wParam equal to VK_PACKET. Once GetMessage or PeekMessage obtains this message, passing the message to TranslateMessage posts a WM_CHAR message with the Unicode character originally specified by wScan. This Unicode character will automatically be converted to the appropriate ANSI value if it is posted to an ANSI window.
根据我的搜索,.NET 似乎没有为您实现此机制,因此您可能必须自己动手!
恐怕我不知道为什么会发生在您的情况下...
老实说,这更像是一种好奇心。
在我正在开发的控制台项目中,我以循环形式请求用户输入:
ConsoleKey response;
Console.Write("Write messages to log? [y/n] ");
response = Console.ReadKey(false).Key;
assume 4 cases:
case 1: Pressing the 'y' key on a keyboard directly atached to the pc running the software.
case 2: Connecting from another computer trough remote desktop connection and pressing the 'y' key on that machine.
case 3: Using on screen keyboard and press the 'y' key trough clicking on it (remotely or locally had no difference)
case 4: Connecting from another machine (specifically a phone) trough chrome remote desktop and pressing the 'y' key.
在情况 1、2 和 3 中,'response' 将包含 'Y'。 如果情况 4 'response' 将包含 System.ConsoleKey.Packet aka 枚举 231 PACKET 键(用于通过击键传递 Unicode 字符)。
我在第二台电脑上尝试了同样的事情,我注意到这种行为似乎没有发生。 最有趣的是控制台向我显示了这个
Write messages to log? [y/n] y
由此我证明确实收到了击键,但我的代码处理不正确。 我不知道如何继续。
Console.ReadLine 会产生正确的击键,但如果可能的话我更愿意使用 Console.ReadKey。
这是 phone 键盘的特定行为吗?我如何获得实际密钥?
How would I obtain the actual key?
MSDN docs for ConsoleKey.Packet
doesn't say anything useful, so I found references to ConsoleKey
in the source which lead here. That's casting ir.keyEvent.virtualKeyCode
to a ConsoleKey
where ir
is an InputRecord
.
快速 google 发现 WinApi 等效项是 INPUT_RECORD
, and chasing the docs through KEY_EVENT_RECORD
leads to this doc of Virtual-Key codes,其中包含 VK_PACKET
的更多文档:
Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP
INPUT_KEYBOARD supports nonkeyboard-input methods—such as handwriting recognition or voice recognition—as if it were text input by using the KEYEVENTF_UNICODE flag. If KEYEVENTF_UNICODE is specified, SendInput sends a WM_KEYDOWN or WM_KEYUP message to the foreground thread's message queue with wParam equal to VK_PACKET. Once GetMessage or PeekMessage obtains this message, passing the message to TranslateMessage posts a WM_CHAR message with the Unicode character originally specified by wScan. This Unicode character will automatically be converted to the appropriate ANSI value if it is posted to an ANSI window.
根据我的搜索,.NET 似乎没有为您实现此机制,因此您可能必须自己动手!
恐怕我不知道为什么会发生在您的情况下...