System.ConsoleKeyInfo.Key是虚拟键码吗?

问题描述 投票:0回答:2

我正在实现我自己的 PSHostRawUserInterface 版本。我想实现 PSHostRawUserInterface.ReadKey(),因此我需要将 System.Management.Automation.Host.KeyInfo.VirtualKeyCode 映射到 System.ConsoleKeyInfo.Key

我可以将 System.ConsoleKeyInfo.Key 转换为 int,我只是不知道这是否实际上是 VirtualKeyCode。

.net windows-console
2个回答
2
投票

认为我不久前对此进行了测试,答案是“是的,但是”。请参阅下文了解注意事项。您可以通过编写一个程序来测试该答案,该程序输出所有ConsoleKey值的整数值并将它们与虚拟按键代码进行比较。

但请注意,

ConsoleKeyInfo.Key
只是键,没有修饰符。虚拟键代码是包含修饰符(Shift、Control、Alt)的位图值。使用
ConsoleKeyInfo
,修饰符存储在
Modifiers
属性中。

或者,您可以将

ConsoleKey
枚举的值与 Keys 枚举的值进行比较,后者明确表示这些值对应于虚拟键代码。


0
投票

我比较了ConsoleKey enum(系统)、Keys enum(System.Windows.Forms)和Virtaul Key Codes。如果我们只保留差异,我们会得到:

© www.soinside.com 2019 - 2024. All rights reserved.