【发布时间】:2021-04-02 19:23:30
【问题描述】:
说实话,这更像是一种好奇心。
在我正在开发的控制台项目中,我以这样的循环形式请求用户输入:
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 中,“响应”将包含“Y”。 如果 4 'response' 将包含 System.ConsoleKey.Packet aka enum 231 PACKET 键(用于通过按键传递 Unicode 字符)。
我在第二台电脑上尝试过同样的事情,我注意到这种行为似乎没有发生。 最有趣的是控制台向我显示了这个
将消息写入日志? [y/n] 是的
据此,我证明确实收到了击键,但我的代码处理不正确。 我不知道如何继续。
Console.ReadLine 输出正确的击键,但如果可能,我更愿意使用 Console.ReadKey。
这是电话键盘的特定行为吗?如何获取实际密钥?
【问题讨论】: