本文整理汇总了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());
}
}
}
}
示例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();
}
示例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());
}
示例4: HandleKeyPress
static void HandleKeyPress(object sender, ConsoleKey key)
{
Console.Clear();
Console.WriteLine("You pressed {0}.", key.ToString());
}
示例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;
}
示例6: HotkeyBarItem
public HotkeyBarItem(ConsoleKey key, string name, HotkeyEvent handler, int gridPosition) : this(key, key.ToString(), name, handler, gridPosition) { }