C#中ConsoleKey如何转换为Key
在C#中,可以使用System.Windows.Forms.Keys枚举来将ConsoleKey转换为Key。
例如,以下代码演示了如何将ConsoleKey.Spacebar转换为Key.Space:
using System;
using System.Windows.Forms;
class Program
{
static void Main(string[] args)
{
ConsoleKey consoleKey = ConsoleKey.Spacebar;
Key key = (Key)Enum.Parse(typeof(Key), consoleKey.ToString(), true);
Console.WriteLine(key);
}
}
输出:Space
原文地址: https://www.cveoy.top/t/topic/b8NU 著作权归作者所有。请勿转载和采集!