在 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

C# 中将 ConsoleKey 转换为 Key 的方法

原文地址: https://www.cveoy.top/t/topic/np4J 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录