ConsoleKey 列舉

定義

指定主控台 (Console) 上的標準按鍵。Specifies the standard keys on a console.

public enum class ConsoleKey
public enum ConsoleKey
[System.Serializable]
public enum ConsoleKey
type ConsoleKey = 
Public Enum ConsoleKey
繼承
ConsoleKey
屬性

欄位

A 65

A 鍵。The A key.

Add 107

加鍵 (數字鍵台上的加法鍵)。The Add key (the addition key on the numeric keypad).

Applications 93

應用程式鍵 (Microsoft Natural Keyboard)。The Application key (Microsoft Natural Keyboard).

Attention 246

ATTN 鍵。The ATTN key.

B 66

B 鍵。The B key.

Backspace 8

退格鍵。The BACKSPACE key.

BrowserBack 166

瀏覽器上一頁鍵。The Browser Back key.

BrowserFavorites 171

瀏覽器我的最愛鍵。The Browser Favorites key.

BrowserForward 167

瀏覽器下一頁鍵。The Browser Forward key.

BrowserHome 172

瀏覽器首頁鍵。The Browser Home key.

BrowserRefresh 168

瀏覽器重新整理鍵。The Browser Refresh key.

BrowserSearch 170

瀏覽器搜尋鍵。The Browser Search key.

BrowserStop 169

瀏覽器停止鍵。The Browser Stop key.

C 67

C 鍵。The C key.

Clear 12

CLEAR 鍵。The CLEAR key.

CrSel 247

CRSEL (CURSOR SELECT) 鍵。The CRSEL (CURSOR SELECT) key.

D 68

D 鍵。The D key.

D0 48

0 鍵。The 0 key.

D1 49

1 鍵。The 1 key.

D2 50

2 鍵。The 2 key.

D3 51

3 鍵。The 3 key.

D4 52

4 鍵。The 4 key.

D5 53

5 鍵。The 5 key.

D6 54

6 鍵。The 6 key.

D7 55

7 鍵。The 7 key.

D8 56

8 鍵。The 8 key.

D9 57

9 鍵。The 9 key.

Decimal 110

小數點鍵 (數字鍵台上的小數點鍵)。The Decimal key (the decimal key on the numeric keypad).

Delete 46

DEL (DELETE) 鍵。The DEL (DELETE) key.

Divide 111

除號鍵 (數字鍵台上的除號鍵)。The Divide key (the division key on the numeric keypad).

DownArrow 40

向下鍵。The DOWN ARROW key.

E 69

E 鍵。The E key.

End 35

END 鍵。The END key.

Enter 13

ENTER 鍵。The ENTER key.

EraseEndOfFile 249

ERASE EOF 鍵。The ERASE EOF key.

Escape 27

ESC (ESCAPE) 鍵。The ESC (ESCAPE) key.

Execute 43

EXECUTE 鍵。The EXECUTE key.

ExSel 248

EXSEL (EXTEND SELECTION) 鍵。The EXSEL (EXTEND SELECTION) key.

F 70

F 鍵。The F key.

F1 112

F1 鍵。The F1 key.

F10 121

F10 鍵。The F10 key.

F11 122

F11 鍵。The F11 key.

F12 123

F12 鍵。The F12 key.

F13 124

F13 鍵。The F13 key.

F14 125

F14 鍵。The F14 key.

F15 126

F15 鍵。The F15 key.

F16 127

F16 鍵。The F16 key.

F17 128

F17 鍵。The F17 key.

F18 129

F18 鍵。The F18 key.

F19 130

F19 鍵。The F19 key.

F2 113

F2 鍵。The F2 key.

F20 131

F20 鍵。The F20 key.

F21 132

F21 鍵。The F21 key.

F22 133

F22 鍵。The F22 key.

F23 134

F23 鍵。The F23 key.

F24 135

F24 鍵。The F24 key.

F3 114

F3 鍵。The F3 key.

F4 115

F4 鍵。The F4 key.

F5 116

F5 鍵。The F5 key.

F6 117

F6 鍵。The F6 key.

F7 118

F7 鍵。The F7 key.

F8 119

F8 鍵。The F8 key.

F9 120

F9 鍵。The F9 key.

G 71

G 鍵。The G key.

H 72

H 鍵。The H key.

Help 47

HELP 鍵。The HELP key.

Home 36

HOME 鍵。The HOME key.

I 73

I 鍵。The I key.

Insert 45

INS (INSERT) 鍵。The INS (INSERT) key.

J 74

J 鍵。The J key.

K 75

K 鍵。The K key.

L 76

L 鍵。The L key.

LaunchApp1 182

啟動應用程式 1 鍵 (Microsoft Natural Keyboard)。The Start Application 1 key (Microsoft Natural Keyboard).

LaunchApp2 183

啟動應用程式 2 鍵 (Microsoft Natural Keyboard)。The Start Application 2 key (Microsoft Natural Keyboard).

LaunchMail 180

啟動郵件鍵 (Microsoft Natural Keyboard)。The Start Mail key (Microsoft Natural Keyboard).

LaunchMediaSelect 181

選取媒體鍵 (Microsoft Natural Keyboard)。The Select Media key (Microsoft Natural Keyboard).

LeftArrow 37

向左鍵。The LEFT ARROW key.

LeftWindows 91

左 Windows 標誌鍵 (Microsoft Natural Keyboard)。The left Windows logo key (Microsoft Natural Keyboard).

M 77

M 鍵。The M key.

MediaNext 176

媒體下一首鍵。The Media Next Track key.

MediaPlay 179

媒體播放/暫停鍵。The Media Play/Pause key.

MediaPrevious 177

媒體上一首鍵。The Media Previous Track key.

MediaStop 178

媒體停止鍵。The Media Stop key.

Multiply 106

乘鍵 (數字鍵台上的乘法鍵)。The Multiply key (the multiplication key on the numeric keypad).

N 78

N 鍵。The N key.

NoName 252

保留供未來使用的常數。A constant reserved for future use.

NumPad0 96

數字鍵台上的 0 鍵。The 0 key on the numeric keypad.

NumPad1 97

數字鍵台上的 1 鍵。The 1 key on the numeric keypad.

NumPad2 98

數字鍵台上的 2 鍵。The 2 key on the numeric keypad.

NumPad3 99

數字鍵台上的 3 鍵。The 3 key on the numeric keypad.

NumPad4 100

數字鍵台上的 4 鍵。The 4 key on the numeric keypad.

NumPad5 101

數字鍵台上的 5 鍵。The 5 key on the numeric keypad.

NumPad6 102

數字鍵台上的 6 鍵。The 6 key on the numeric keypad.

NumPad7 103

數字鍵台上的 7 鍵。The 7 key on the numeric keypad.

NumPad8 104

數字鍵台上的 8 鍵。The 8 key on the numeric keypad.

NumPad9 105

數字鍵台上的 9 鍵。The 9 key on the numeric keypad.

O 79

O 鍵。The O key.

Oem1 186

OEM 1 鍵 (OEM 特定)。The OEM 1 key (OEM specific).

Oem102 226

OEM 102 鍵 (OEM 特定)。The OEM 102 key (OEM specific).

Oem2 191

OEM 2 鍵 (OEM 特定)。The OEM 2 key (OEM specific).

Oem3 192

OEM 3 鍵 (OEM 特定)。The OEM 3 key (OEM specific).

Oem4 219

OEM 4 鍵 (OEM 特定)。The OEM 4 key (OEM specific).

Oem5 220

OEM 5 鍵 (OEM 特定)。The OEM 5 (OEM specific).

Oem6 221

OEM 6 鍵 (OEM 特定)。The OEM 6 key (OEM specific).

Oem7 222

OEM 7 鍵 (OEM 特定)。The OEM 7 key (OEM specific).

Oem8 223

OEM 8 鍵 (OEM 特定)。The OEM 8 key (OEM specific).

OemClear 254

CLEAR 鍵 (OEM 特定)。The CLEAR key (OEM specific).

OemComma 188

任何國家/地區鍵盤上的 OEM 逗號鍵。The OEM Comma key on any country/region keyboard.

OemMinus 189

任何國家/地區鍵盤上的 OEM 減號鍵。The OEM Minus key on any country/region keyboard.

OemPeriod 190

任何國家/地區鍵盤上的 OEM 句號鍵。The OEM Period key on any country/region keyboard.

OemPlus 187

任何國家/地區鍵盤上的 OEM 加號鍵。The OEM Plus key on any country/region keyboard.

P 80

P 鍵。The P key.

Pa1 253

PA1 鍵。The PA1 key.

Packet 231

PACKET 鍵 (用來以按鍵傳遞 Unicode 字元)。The PACKET key (used to pass Unicode characters with keystrokes).

PageDown 34

PAGE DOWN 鍵。The PAGE DOWN key.

PageUp 33

PAGE UP 鍵。The PAGE UP key.

Pause 19

PAUSE 鍵。The PAUSE key.

Play 250

PLAY 鍵。The PLAY key.

Print 42

PLAY 鍵。The PRINT key.

PrintScreen 44

PRINT SCREEN 鍵。The PRINT SCREEN key.

Process 229

輸入法 PROCESS 鍵。The IME PROCESS key.

Q 81

Q 鍵。The Q key.

R 82

R 鍵。The R key.

RightArrow 39

向右鍵。The RIGHT ARROW key.

RightWindows 92

右 Windows 標誌鍵 (Microsoft Natural Keyboard)。The right Windows logo key (Microsoft Natural Keyboard).

S 83

S 鍵。The S key.

Select 41

SELECT 鍵。The SELECT key.

Separator 108

分隔符號鍵。The Separator key.

Sleep 95

電腦睡眠鍵。The Computer Sleep key.

Spacebar 32

空格鍵。The SPACEBAR key.

Subtract 109

減號鍵 (數字鍵台上的減號鍵)。The Subtract key (the subtraction key on the numeric keypad).

T 84

T 鍵。The T key.

Tab 9

TAB 鍵。The TAB key.

U 85

U 鍵。The U key.

UpArrow 38

向上鍵。The UP ARROW key.

V 86

V 鍵。The V key.

VolumeDown 174

音量降低鍵 (Microsoft Natural Keyboard)。The Volume Down key (Microsoft Natural Keyboard).

VolumeMute 173

靜音鍵 (Microsoft Natural Keyboard)。The Volume Mute key (Microsoft Natural Keyboard).

VolumeUp 175

音量提高鍵 (Microsoft Natural Keyboard)。The Volume Up key (Microsoft Natural Keyboard).

W 87

W 鍵。The W key.

X 88

X 鍵。The X key.

Y 89

Y 鍵。The Y key.

Z 90

Z 鍵。The Z key.

Zoom 251

ZOOM 鍵。The ZOOM key.

範例

下列範例會使用 ConsoleKey 列舉,向使用者指出使用者已按下哪一個金鑰。The following example uses the ConsoleKey enumeration to indicate to the user which key the user had pressed.

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. 
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 方法傳回,以指出已按下主控台上的哪個按鍵。The ConsoleKey enumeration is typically used in the nfo structure, which is returned by the Console.ReadKey method to indicate which key on the console has been pressed.

適用於