ConsoleKey 列舉
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定主控台 (Console) 上的標準按鍵。
public enum class ConsoleKey
public enum ConsoleKey
[System.Serializable]
public enum ConsoleKey
type ConsoleKey =
[<System.Serializable>]
type ConsoleKey =
Public Enum ConsoleKey
- 繼承
- 屬性
欄位
| 名稱 | 值 | Description |
|---|---|---|
| A | 65 | A 鍵。 |
| Add | 107 | 加鍵 (數字鍵台上的加法鍵)。 |
| Applications | 93 | 應用程式鍵 (Microsoft Natural Keyboard)。 |
| Attention | 246 | ATTN 鍵。 |
| B | 66 | B 鍵。 |
| Backspace | 8 | 退格鍵。 |
| BrowserBack | 166 | 瀏覽器上一頁鍵。 |
| BrowserFavorites | 171 | 瀏覽器我的最愛鍵。 |
| BrowserForward | 167 | 瀏覽器下一頁鍵。 |
| BrowserHome | 172 | 瀏覽器首頁鍵。 |
| BrowserRefresh | 168 | 瀏覽器重新整理鍵。 |
| BrowserSearch | 170 | 瀏覽器搜尋鍵。 |
| BrowserStop | 169 | 瀏覽器停止鍵。 |
| C | 67 | C 鍵。 |
| Clear | 12 | CLEAR 鍵。 |
| CrSel | 247 | CRSEL (CURSOR SELECT) 鍵。 |
| D | 68 | D 鍵。 |
| D0 | 48 | 0 鍵。 |
| D1 | 49 | 1 鍵。 |
| D2 | 50 | 2 鍵。 |
| D3 | 51 | 3 鍵。 |
| D4 | 52 | 4 鍵。 |
| D5 | 53 | 5 鍵。 |
| D6 | 54 | 6 鍵。 |
| D7 | 55 | 7 鍵。 |
| D8 | 56 | 8 鍵。 |
| D9 | 57 | 9 鍵。 |
| Decimal | 110 | 小數點鍵 (數字鍵台上的小數點鍵)。 |
| Delete | 46 | DEL (DELETE) 鍵。 |
| Divide | 111 | 除號鍵 (數字鍵台上的除號鍵)。 |
| DownArrow | 40 | 向下鍵。 |
| E | 69 | E 鍵。 |
| End | 35 | END 鍵。 |
| Enter | 13 | ENTER 鍵。 |
| EraseEndOfFile | 249 | ERASE EOF 鍵。 |
| Escape | 27 | ESC (ESCAPE) 鍵。 |
| Execute | 43 | EXECUTE 鍵。 |
| ExSel | 248 | EXSEL (EXTEND SELECTION) 鍵。 |
| F | 70 | F 鍵。 |
| F1 | 112 | F1 鍵。 |
| F10 | 121 | F10 鍵。 |
| F11 | 122 | F11 鍵。 |
| F12 | 123 | F12 鍵。 |
| F13 | 124 | F13 鍵。 |
| F14 | 125 | F14 鍵。 |
| F15 | 126 | F15 鍵。 |
| F16 | 127 | F16 鍵。 |
| F17 | 128 | F17 鍵。 |
| F18 | 129 | F18 鍵。 |
| F19 | 130 | F19 鍵。 |
| F2 | 113 | F2 鍵。 |
| F20 | 131 | F20 鍵。 |
| F21 | 132 | F21 鍵。 |
| F22 | 133 | F22 鍵。 |
| F23 | 134 | F23 鍵。 |
| F24 | 135 | F24 鍵。 |
| F3 | 114 | F3 鍵。 |
| F4 | 115 | F4 鍵。 |
| F5 | 116 | F5 鍵。 |
| F6 | 117 | F6 鍵。 |
| F7 | 118 | F7 鍵。 |
| F8 | 119 | F8 鍵。 |
| F9 | 120 | F9 鍵。 |
| G | 71 | G 鍵。 |
| H | 72 | H 鍵。 |
| Help | 47 | HELP 鍵。 |
| Home | 36 | HOME 鍵。 |
| I | 73 | I 鍵。 |
| Insert | 45 | INS (INSERT) 鍵。 |
| J | 74 | J 鍵。 |
| K | 75 | K 鍵。 |
| L | 76 | L 鍵。 |
| LaunchApp1 | 182 | 啟動應用程式 1 鍵 (Microsoft Natural Keyboard)。 |
| LaunchApp2 | 183 | 啟動應用程式 2 鍵 (Microsoft Natural Keyboard)。 |
| LaunchMail | 180 | 啟動郵件鍵 (Microsoft Natural Keyboard)。 |
| LaunchMediaSelect | 181 | 選取媒體鍵 (Microsoft Natural Keyboard)。 |
| LeftArrow | 37 | 向左鍵。 |
| LeftWindows | 91 | 左 Windows 標誌鍵 (Microsoft Natural Keyboard)。 |
| M | 77 | M 鍵。 |
| MediaNext | 176 | 媒體下一首鍵。 |
| MediaPlay | 179 | 媒體播放/暫停鍵。 |
| MediaPrevious | 177 | 媒體上一首鍵。 |
| MediaStop | 178 | 媒體停止鍵。 |
| Multiply | 106 | 乘號鍵 (數字鍵台上的乘號鍵)。 |
| N | 78 | N 鍵。 |
| NoName | 252 | 保留供未來使用的常數。 |
| NumPad0 | 96 | 數字鍵台上的 0 鍵。 |
| NumPad1 | 97 | 數字鍵台上的 1 鍵。 |
| NumPad2 | 98 | 數字鍵台上的 2 鍵。 |
| NumPad3 | 99 | 數字鍵台上的 3 鍵。 |
| NumPad4 | 100 | 數字鍵台上的 4 鍵。 |
| NumPad5 | 101 | 數字鍵台上的 5 鍵。 |
| NumPad6 | 102 | 數字鍵台上的 6 鍵。 |
| NumPad7 | 103 | 數字鍵台上的 7 鍵。 |
| NumPad8 | 104 | 數字鍵台上的 8 鍵。 |
| NumPad9 | 105 | 數字鍵台上的 9 鍵。 |
| O | 79 | O 鍵。 |
| Oem1 | 186 | OEM 1 鍵 (OEM 特定)。 |
| Oem102 | 226 | OEM 102 鍵 (OEM 特定)。 |
| Oem2 | 191 | OEM 2 鍵 (OEM 特定)。 |
| Oem3 | 192 | OEM 3 鍵 (OEM 特定)。 |
| Oem4 | 219 | OEM 4 鍵 (OEM 特定)。 |
| Oem5 | 220 | OEM 5 鍵 (OEM 特定)。 |
| Oem6 | 221 | OEM 6 鍵 (OEM 特定)。 |
| Oem7 | 222 | OEM 7 鍵 (OEM 特定)。 |
| Oem8 | 223 | OEM 8 鍵 (OEM 特定)。 |
| OemClear | 254 | CLEAR 鍵 (OEM 特定)。 |
| OemComma | 188 | 任何國家/地區鍵盤上的 OEM 逗號鍵。 |
| OemMinus | 189 | 任何國家/地區鍵盤上的 OEM 減號鍵。 |
| OemPeriod | 190 | 任何國家/地區鍵盤上的 OEM 句號鍵。 |
| OemPlus | 187 | 任何國家/地區鍵盤上的 OEM 加號鍵。 |
| P | 80 | P 鍵。 |
| Pa1 | 253 | PA1 鍵。 |
| Packet | 231 | PACKET 鍵 (用來以按鍵傳遞 Unicode 字元)。 |
| PageDown | 34 | PAGE DOWN 鍵。 |
| PageUp | 33 | PAGE UP 鍵。 |
| Pause | 19 | PAUSE 鍵。 |
| Play | 250 | PLAY 鍵。 |
| 42 | PLAY 鍵。 |
|
| PrintScreen | 44 | PRINT SCREEN 鍵。 |
| Process | 229 | 輸入法 PROCESS 鍵。 |
| Q | 81 | Q 鍵。 |
| R | 82 | R 鍵。 |
| RightArrow | 39 | 向右鍵。 |
| RightWindows | 92 | 右 Windows 標誌鍵 (Microsoft Natural Keyboard)。 |
| S | 83 | S 鍵。 |
| Select | 41 | SELECT 鍵。 |
| Separator | 108 | 分隔符號鍵。 |
| Sleep | 95 | 電腦睡眠鍵。 |
| Spacebar | 32 | 空格鍵。 |
| Subtract | 109 | 減號鍵 (數字鍵台上的減號鍵)。 |
| T | 84 | T 鍵。 |
| Tab | 9 | TAB 鍵。 |
| U | 85 | U 鍵。 |
| UpArrow | 38 | 向上鍵。 |
| V | 86 | V 鍵。 |
| VolumeDown | 174 | 音量降低鍵 (Microsoft Natural Keyboard)。 |
| VolumeMute | 173 | 靜音鍵 (Microsoft Natural Keyboard)。 |
| VolumeUp | 175 | 音量提高鍵 (Microsoft Natural Keyboard)。 |
| W | 87 | W 鍵。 |
| X | 88 | X 鍵。 |
| Y | 89 | Y 鍵。 |
| Z | 90 | Z 鍵。 |
| Zoom | 251 | ZOOM 鍵。 |
範例
下列範例會 ConsoleKey 使用 列舉,向使用者指出使用者按下的按鍵。
using namespace System;
using namespace System::Text;
void main()
{
ConsoleKeyInfo input;
do {
Console::WriteLine("Press a key, together with Alt, Ctrl, or Shift.");
Console::WriteLine("Press Esc to exit.");
input = Console::ReadKey(true);
StringBuilder^ output = gcnew StringBuilder(
String::Format("You pressed {0}", input.Key.ToString()));
bool modifiers = false;
if ((input.Modifiers & ConsoleModifiers::Alt) == ConsoleModifiers::Alt) {
output->Append(", together with " + ConsoleModifiers::Alt.ToString());
modifiers = true;
}
if ((input.Modifiers & ConsoleModifiers::Control) == ConsoleModifiers::Control)
{
if (modifiers) {
output->Append(" and ");
}
else {
output->Append(", together with ");
modifiers = true;
}
output->Append(ConsoleModifiers::Control.ToString());
}
if ((input.Modifiers & ConsoleModifiers::Shift) == ConsoleModifiers::Shift)
{
if (modifiers) {
output->Append(" and ");
}
else {
output->Append(", together with ");
modifiers = true;
}
output->Append(ConsoleModifiers::Shift.ToString());
}
output->Append(".");
Console::WriteLine(output->ToString());
Console::WriteLine();
} while (input.Key != ConsoleKey::Escape);
}
// The output from a sample console session might appear as follows:
// Press a key, along with Alt, Ctrl, or Shift.
// Press Esc to exit.
// You pressed D.
//
// Press a key, along with Alt, Ctrl, or Shift.
// Press Esc to exit.
// You pressed X, along with Shift.
//
// Press a key, along with Alt, Ctrl, or Shift.
// Press Esc to exit.
// You pressed L, along with Control and Shift.
//
// Press a key, along with Alt, Ctrl, or Shift.
// Press Esc to exit.
// You pressed P, along with Alt and Control and Shift.
//
// Press a key, along with Alt, Ctrl, or Shift.
// Press Esc to exit.
// You pressed Escape.
using System;
using System.Text;
public class ConsoleKeyExample
{
public static void Main()
{
ConsoleKeyInfo input;
do {
Console.WriteLine("Press a key, together with Alt, Ctrl, or Shift.");
Console.WriteLine("Press Esc to exit.");
input = Console.ReadKey(true);
StringBuilder output = new StringBuilder(
String.Format("You pressed {0}", input.Key.ToString()));
bool modifiers = false;
if ((input.Modifiers & ConsoleModifiers.Alt) == ConsoleModifiers.Alt) {
output.Append(", together with " + ConsoleModifiers.Alt.ToString());
modifiers = true;
}
if ((input.Modifiers & ConsoleModifiers.Control) == ConsoleModifiers.Control)
{
if (modifiers) {
output.Append(" and ");
}
else {
output.Append(", together with ");
modifiers = true;
}
output.Append(ConsoleModifiers.Control.ToString());
}
if ((input.Modifiers & ConsoleModifiers.Shift) == ConsoleModifiers.Shift)
{
if (modifiers) {
output.Append(" and ");
}
else {
output.Append(", together with ");
modifiers = true;
}
output.Append(ConsoleModifiers.Shift.ToString());
}
output.Append(".");
Console.WriteLine(output.ToString());
Console.WriteLine();
} while (input.Key != ConsoleKey.Escape);
}
}
// The output from a sample console session might appear as follows:
// Press a key, along with Alt, Ctrl, or Shift.
// Press Esc to exit.
// You pressed D.
//
// Press a key, along with Alt, Ctrl, or Shift.
// Press Esc to exit.
// You pressed X, along with Shift.
//
// Press a key, along with Alt, Ctrl, or Shift.
// Press Esc to exit.
// You pressed L, along with Control and Shift.
//
// Press a key, along with Alt, Ctrl, or Shift.
// Press Esc to exit.
// You pressed P, along with Alt and Control and Shift.
//
// Press a key, along with Alt, Ctrl, or Shift.
// Press Esc to exit.
// You pressed Escape.
open System
open System.Text
let mutable input = Unchecked.defaultof<ConsoleKeyInfo>
while input.Key <> ConsoleKey.Escape do
printfn "Press a key, together with Alt, Ctrl, or Shift."
printfn "Press Esc to exit."
input <- Console.ReadKey true
let output = StringBuilder $"You pressed {input.Key}"
let mutable modifiers = false
if input.Modifiers &&& ConsoleModifiers.Alt = ConsoleModifiers.Alt then
output.Append ", together with {ConsoleModifiers.Alt}" |> ignore
modifiers <- true
if input.Modifiers &&& ConsoleModifiers.Control = ConsoleModifiers.Control then
if modifiers then
output.Append " and " |> ignore
else
output.Append ", together with " |> ignore
modifiers <- true
output.Append(string ConsoleModifiers.Control) |> ignore
if input.Modifiers &&& ConsoleModifiers.Shift = ConsoleModifiers.Shift then
if modifiers then
output.Append " and " |> ignore
else
output.Append ", together with " |> ignore
modifiers <- true
output.Append(string ConsoleModifiers.Shift) |> ignore
output.Append "." |> ignore
printfn $"{output}\n"
// The output from a sample console session might appear as follows:
// Press a key, along with Alt, Ctrl, or Shift.
// Press Esc to exit.
// You pressed D.
//
// Press a key, along with Alt, Ctrl, or Shift.
// Press Esc to exit.
// You pressed X, along with Shift.
//
// Press a key, along with Alt, Ctrl, or Shift.
// Press Esc to exit.
// You pressed L, along with Control and Shift.
//
// Press a key, along with Alt, Ctrl, or Shift.
// Press Esc to exit.
// You pressed P, along with Alt and Control and Shift.
//
// Press a key, along with Alt, Ctrl, or Shift.
// Press Esc to exit.
// You pressed Escape.
Imports System.Text
Module ConsoleKeyExample
Public Sub Main()
Dim input As ConsoleKeyInfo
Do
Console.WriteLine("Press a key, together with Alt, Ctrl, or Shift.")
Console.WriteLine("Press Esc to exit.")
input = Console.ReadKey(True)
Dim output As New StringBuilder(String.Format("You pressed {0}", input.Key.ToString()))
Dim modifiers As Boolean
If (input.Modifiers And ConsoleModifiers.Alt) = ConsoleModifiers.Alt Then
output.Append(", together with " + ConsoleModifiers.Alt.ToString())
modifiers = True
End If
If (input.Modifiers And ConsoleModifiers.Control) = ConsoleModifiers.Control Then
If modifiers Then
output.Append(" and ")
Else
output.Append(", together with ")
modifiers = True
End If
output.Append(ConsoleModifiers.Control.ToString)
End If
If (input.Modifiers And ConsoleModifiers.Shift) = ConsoleModifiers.Shift Then
If modifiers Then
output.Append(" and ")
Else
output.Append(", together with ")
End If
output.Append(ConsoleModifiers.Shift.ToString)
End If
output.Append(".")
Console.WriteLine(output.ToString())
Console.WriteLine()
Loop While input.Key <> ConsoleKey.Escape
End Sub
End Module
' The output from a sample console session might appear as follows:
' Press a key, along with Alt, Ctrl, or Shift.
' Press Esc to exit.
' You pressed D.
'
' Press a key, along with Alt, Ctrl, or Shift.
' Press Esc to exit.
' You pressed X, along with Shift.
'
' Press a key, along with Alt, Ctrl, or Shift.
' Press Esc to exit.
' You pressed L, along with Control and Shift.
'
' Press a key, along with Alt, Ctrl, or Shift.
' Press Esc to exit.
' You pressed P, along with Alt and Control and Shift.
'
' Press a key, along with Alt, Ctrl, or Shift.
' Press Esc to exit.
' You pressed Escape.
備註
列舉 ConsoleKey 通常用於 nfo 結構中,此方法會傳 Console.ReadKey 回這個結構,以指出已按下主控台上的哪一個索引鍵。