当前位置: 首页>>代码示例>>C#>>正文


C# ConsoleKey.ToString方法代码示例

本文整理汇总了C#中ConsoleKey.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ConsoleKey.ToString方法的具体用法?C# ConsoleKey.ToString怎么用?C# ConsoleKey.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConsoleKey的用法示例。


在下文中一共展示了ConsoleKey.ToString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckKey

 public static bool CheckKey(ConsoleKey yesKey, ConsoleKey noKey)
 {
     while (true)
     {
         if (Console.KeyAvailable)
         {
             ConsoleKeyInfo info = Console.ReadKey(true);
             if (info.Key == yesKey)
             {
                 return true;
             }
             else if (info.Key == noKey)
             {
                 return false;
             }
             else
             {
                 Console.WriteLine("Key not reconized. Press {0} for Yes or {1} for No",
                     yesKey.ToString(), noKey.ToString());
             }
         }
     }
 }
开发者ID:TeamOscarWilde,项目名称:FantasyIsland,代码行数:23,代码来源:Reaction.cs

示例2: GetKeyChar


//.........这里部分代码省略.........
                case ConsoleKey.Q:
                    return ShiftPressed || CapsLockOn ? "Q" : "q";
                case ConsoleKey.R:
                    return ShiftPressed || CapsLockOn ? "R" : "r";
                case ConsoleKey.S:
                    return ShiftPressed || CapsLockOn ? "S" : "s";
                case ConsoleKey.T:
                    return ShiftPressed || CapsLockOn ? "T" : "t";
                case ConsoleKey.U:
                    return ShiftPressed || CapsLockOn ? "U" : "u";
                case ConsoleKey.V:
                    return ShiftPressed || CapsLockOn ? "V" : "v";
                case ConsoleKey.W:
                    return ShiftPressed || CapsLockOn ? "W" : "w";
                case ConsoleKey.X:
                    return ShiftPressed || CapsLockOn ? "X" : "x";
                case ConsoleKey.Y:
                    return ShiftPressed || CapsLockOn ? "Y" : "y";
                case ConsoleKey.Z:
                    return ShiftPressed || CapsLockOn ? "Z" : "z";

                // Numpad keys
                case ConsoleKey.NumPad0:
                    return "0";
                case ConsoleKey.NumPad1:
                    return "1";
                case ConsoleKey.NumPad2:
                    return "2";
                case ConsoleKey.NumPad3:
                    return "3";
                case ConsoleKey.NumPad4:
                    return "4";
                case ConsoleKey.NumPad5:
                    return "5";
                case ConsoleKey.NumPad6:
                    return "6";
                case ConsoleKey.NumPad7:
                    return "7";
                case ConsoleKey.NumPad8:
                    return "8";
                case ConsoleKey.NumPad9:
                    return "9";

                // Keys below F1-F8.
                case ConsoleKey.D0:
                    return ShiftPressed ? "=" : "0";
                case ConsoleKey.D1:
                    return ShiftPressed ? "!" : "1";
                case ConsoleKey.D2:
                    return ShiftPressed ? "\"" : "2";
                case ConsoleKey.D3:
                    return ShiftPressed ? "#" : "3";
                case ConsoleKey.D4:
                    return ShiftPressed ? "¤" : "4";
                case ConsoleKey.D5:
                    return ShiftPressed ? "%" : "5";
                case ConsoleKey.D6:
                    return ShiftPressed ? "&" : "6";
                case ConsoleKey.D7:
                    return ShiftPressed ? "/" : "7";
                case ConsoleKey.D8:
                    return ShiftPressed ? "(" : "8";
                case ConsoleKey.D9:
                    return ShiftPressed ? ")" : "9";

                // Special characters.
                case ConsoleKey.Spacebar:
                    return " ";
                case ConsoleKey.Tab:
                    return "\t";
                case ConsoleKey.Backspace:
                    return "\b";
                case ConsoleKey.Enter:
                    return "\n";
                case ConsoleKey.Multiply:
                    return "*";
                case ConsoleKey.Add:
                    return ShiftPressed ? "?" : "+";
                case ConsoleKey.Subtract:
                    return "-";

                // Oem keys
                case ConsoleKey.OemComma:
                    return ShiftPressed ? ";" : ",";
                case ConsoleKey.OemPeriod:
                    return ShiftPressed ? ":" : ".";
                case ConsoleKey.OemMinus:
                    return ShiftPressed ? "_" : "-";
                case ConsoleKey.OemPlus:
                    return ShiftPressed ? "?" : "+";
                case ConsoleKey.Oem4:
                    return ShiftPressed ? "`" : "´";
                case ConsoleKey.Oem5:
                    return ShiftPressed ? "½" : "§";
                case ConsoleKey.Oem102:
                    return ShiftPressed ? ">" : "<";
            }

            return key.ToString();
        }
开发者ID:Skippeh,项目名称:Learning-Networking,代码行数:101,代码来源:InputManager.cs

示例3: SmartRead


//.........这里部分代码省略.........
                case ConsoleKey.LeftArrow:
                    MoveLeft();
                    return;
                case ConsoleKey.RightArrow:
                    MoveRight();
                    return;
                case ConsoleKey.Multiply:
                    msg = "*";
                    break;
                case ConsoleKey.D1:
                    if (Caps == 1)
                        msg = "!";
                    else if (Caps == 2)
                        msg = "1";
                    break;
                case ConsoleKey.D2:
                    if (Caps == 1)
                        msg = "\"";
                    else if (Caps == 2)
                        msg = "2";
                    break;
                case ConsoleKey.D3:
                    if (Caps == 1)
                        msg = "£";
                    else if (Caps == 2)
                        msg = "3";
                    break;
                case ConsoleKey.D4:
                    if (Caps == 1)
                        msg = "$";
                    else if (Caps == 2)
                        msg = "4";
                    break;
                case ConsoleKey.D5:
                    if (Caps == 1)
                        msg = "%";
                    else if (Caps == 2)
                        msg = "5";
                    break;
                case ConsoleKey.D6:
                    if (Caps == 1)
                        msg = "^";
                    else if (Caps == 2)
                        msg = "6";
                    break;
                case ConsoleKey.D7:
                    if (Caps == 1)
                        msg = "&";
                    else if (Caps == 2)
                        msg = "7";
                    break;
                case ConsoleKey.D8:
                    if (Caps == 1)
                        msg = "*";
                    else if (Caps == 2)
                        msg = "8";
                    break;
                case ConsoleKey.D9:
                    if (Caps == 1)
                        msg = "(";
                    else if (Caps == 2)
                        msg = "9";
                    break;
                case ConsoleKey.D0:
                    if (Caps == 1)
                        msg = ")";
                    else if (Caps == 2)
                        msg = "0";
                    break;
                case ConsoleKey.Subtract:
                    msg = "-";
                    break;
                case ConsoleKey.Divide:
                    msg = "/";
                    break;
                case ConsoleKey.Oem8:
                    if (Caps == 1)
                        msg = "¬";
                    else if (Caps == 2)
                        msg = "`";
                    break;
                case ConsoleKey.OemMinus:
                    if (Caps == 1)
                        msg = "_";
                    else if (Caps == 2)
                        msg = "-";
                    break;
                case ConsoleKey.OemPlus:
                    if (Caps == 1)
                        msg = "+";
                    else if (Caps == 2)
                        msg = "=";
                    break;
                default:
                    msg = key.ToString();
                    break;
            }

            SmartWrite(BufferLocation++, ConsoleHeight - 1, this.Caps == 1 ? msg : msg.ToLower());
        }
开发者ID:gunnerwolf,项目名称:Quot,代码行数:101,代码来源:CLUI.cs

示例4: HandleKeyPress

    static void HandleKeyPress(object sender, ConsoleKey key)
    {
        Console.Clear();

        Console.WriteLine("You pressed {0}.", key.ToString());
    }
开发者ID:dgrigorov,项目名称:TelerikAcademy-1,代码行数:6,代码来源:Program.cs

示例5: GetShortCutKeyDisplay

 /// <summary>
 /// 取按键的显示内容
 /// </summary>
 public static string GetShortCutKeyDisplay(ConsoleKey ck)
 {
     var s = ck.ToString();
     if (s.Length == 2 && s[0] == 'D') s = s[1].ToString();  //处理 D1 D2 ... 的问题
     //陆续添加中
     return s;
 }
开发者ID:TheLegion96,项目名称:fightthelandlord,代码行数:10,代码来源:MenuItem.cs

示例6: HotkeyBarItem

 public HotkeyBarItem(ConsoleKey key, string name, HotkeyEvent handler, int gridPosition) : this(key, key.ToString(), name, handler, gridPosition) { }
开发者ID:mkibiger,项目名称:CursorAreaLock,代码行数:1,代码来源:HotkeyBar.cs


注:本文中的ConsoleKey.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。