ConsoleKey Перечисление

Определение

Указывает стандартные ключи в консоли.

public enum class ConsoleKey
public enum ConsoleKey
[System.Serializable]
public enum ConsoleKey
type ConsoleKey = 
[<System.Serializable>]
type ConsoleKey = 
Public Enum ConsoleKey
Наследование
ConsoleKey
Атрибуты

Поля

Имя Значение Описание
None 0
Backspace 8

Ключ BACKSPACE.

Tab 9

Клавиша TAB.

Clear 12

Ключ CLEAR.

Enter 13

Клавиша ВВОД.

Pause 19

Клавиша PAUSE.

Escape 27

Ключ ESC (ESCAPE).

Spacebar 32

Клавиша SPACEBAR.

PageUp 33

Клавиша PAGE UP.

PageDown 34

Клавиша PAGE DOWN.

End 35

Ключ END.

Home 36

Ключ HOME.

LeftArrow 37

Клавиша СТРЕЛКА ВЛЕВО.

UpArrow 38

Клавиша СТРЕЛКА ВВЕРХ.

RightArrow 39

Клавиша СТРЕЛКА ВПРАВО.

DownArrow 40

Клавиша СТРЕЛКА ВНИЗ.

Select 41

Ключ SELECT.

Print 42

Ключ PRINT.

Execute 43

Ключ EXECUTE.

PrintScreen 44

Клавиша PRINT SCREEN.

Insert 45

Ключ INS (INSERT).

Delete 46

Ключ DEL (DELETE).

Help 47

Ключ HELP.

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.

A 65

Ключ A.

B 66

Клавиша B.

C 67

Ключ C.

D 68

Клавиша D.

E 69

Клавиша E.

F 70

Клавиша F.

G 71

Клавиша G.

H 72

Ключ H.

I 73

Клавиша I.

J 74

Ключ J.

K 75

Клавиша K.

L 76

Ключ L.

M 77

Клавиша M.

N 78

Клавиша N.

O 79

Клавиша O.

P 80

Ключ P.

Q 81

Ключ Q.

R 82

Ключ R.

S 83

Ключ S.

T 84

Клавиша T.

U 85

Ключ U.

V 86

Клавиша V.

W 87

Клавиша W.

X 88

Клавиша X.

Y 89

Ключ Y.

Z 90

Клавиша Z.

LeftWindows 91

Левая Windows клавиша с логотипом (Microsoft естественной клавиатуры).

RightWindows 92

Правый Windows клавиша логотипа (Microsoft естественной клавиатуры).

Applications 93

Клавиша приложения (Microsoft естественной клавиатуры).

Sleep 95

Ключ спящего режима компьютера.

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 клавиша на числовой клавиатуре.

Multiply 106

Ключ умножения (ключ умножения на числовой клавиатуре).

Add 107

Клавиша Add (клавиша добавления на числовой клавиатуре).

Separator 108

Ключ разделителя.

Subtract 109

Вычитание ключа (ключ вычитания на числовой клавиатуре).

Decimal 110

Десятичный ключ (десятичный ключ на числовой клавиатуре).

Divide 111

Ключ деления (ключ деления на числовой клавиатуре).

F1 112

Клавиша F1.

F2 113

Клавиша F2.

F3 114

Клавиша F3.

F4 115

Клавиша F4.

F5 116

Клавиша F5.

F6 117

Клавиша F6.

F7 118

Клавиша F7.

F8 119

Клавиша F8.

F9 120

Клавиша F9.

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.

F20 131

Клавиша F20.

F21 132

Ключ F21.

F22 133

Ключ F22.

F23 134

Ключ F23.

F24 135

Клавиша F24.

BrowserBack 166

Ключ обратного браузера.

BrowserForward 167

Ключ пересылки браузера.

BrowserRefresh 168

Ключ обновления браузера.

BrowserStop 169

Ключ остановки браузера.

BrowserSearch 170

Ключ поиска в браузере.

BrowserFavorites 171

Ключ избранного браузера.

BrowserHome 172

Ключ домашнего браузера.

VolumeMute 173

Клавиша выключения тома (Microsoft естественной клавиатуры).

VolumeDown 174

Клавиша "Вниз тома" (Microsoft естественной клавиатуры).

VolumeUp 175

Клавиша "Вверх тома" (Microsoft естественной клавиатуры).

MediaNext 176

Ключ следующего отслеживания мультимедиа.

MediaPrevious 177

Ключ предыдущей дорожки мультимедиа.

MediaStop 178

Ключ остановки мультимедиа.

MediaPlay 179

Клавиша воспроизведения и приостановки мультимедиа.

LaunchMail 180

Клавиша "Пуск почта" (Microsoft естественной клавиатуры).

LaunchMediaSelect 181

Клавиша выбора носителя (Microsoft естественной клавиатуры).

LaunchApp1 182

Клавиша Start Application 1 (Microsoft естественной клавиатуры).

LaunchApp2 183

Клавиша Start Application 2 (Microsoft естественной клавиатуры).

Oem1 186

Ключ OEM 1 (oem specific).

OemPlus 187

Клавиша OEM Plus на любой клавиатуре страны или региона.

OemComma 188

Клавиша запятой OEM на любой клавиатуре страны или региона.

OemMinus 189

Клавиша OEM Минус на любой клавиатуре страны или региона.

OemPeriod 190

Клавиша "Период OEM" на любой клавиатуре страны или региона.

Oem2 191

Ключ OEM 2 (oem specific).

Oem3 192

Ключ OEM 3 (oem specific).

Oem4 219

Ключ OEM 4 (oem specific).

Oem5 220

OEM 5 (oem specific).

Oem6 221

Ключ OEM 6 (oem specific).

Oem7 222

Ключ OEM 7 (oem specific).

Oem8 223

Ключ OEM 8 (oem specific).

Oem102 226

Ключ OEM 102 (oem specific).

Process 229

Ключ процесса IME.

Packet 231

Ключ PACKET (используется для передачи символов Юникода с нажатиями клавиш).

Attention 246

Ключ ATTN.

CrSel 247

Ключ CRSEL (CURSOR SELECT).

ExSel 248

Ключ EXSEL (EXTEND SELECTION).

EraseEndOfFile 249

Ключ ERASE EOF.

Play 250

Ключ PLAY.

Zoom 251

Ключ ZOOM.

NoName 252

Константы, зарезервированные для будущего использования.

Pa1 253

Ключ PA1.

OemClear 254

Ключ CLEAR (конкретный изготовитель оборудования).

Примеры

В следующем примере перечисление ConsoleKey используется для указания пользователю, какой ключ нажат.

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.HasFlag(ConsoleModifiers.Alt)) {
            output.Append(", together with " + ConsoleModifiers.Alt.ToString());
            modifiers = true;
         }
         if (input.Modifiers.HasFlag(ConsoleModifiers.Control))
         {
            if (modifiers) {
               output.Append(" and ");
            }
            else {
               output.Append(", together with ");
               modifiers = true;
            }
            output.Append(ConsoleModifiers.Control.ToString());
         }
         if (input.Modifiers.HasFlag(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, together with Alt, Ctrl, or Shift.
//       Press Esc to exit.
//       You pressed D.
//
//       Press a key, together with Alt, Ctrl, or Shift.
//       Press Esc to exit.
//       You pressed X, together with Shift.
//
//       Press a key, together with Alt, Ctrl, or Shift.
//       Press Esc to exit.
//       You pressed L, together with Control and Shift.
//
//       Press a key, together with Alt, Ctrl, or Shift.
//       Press Esc to exit.
//       You pressed P, together with Alt and Control and Shift.
//
//       Press a key, together 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 , чтобы указать, какой ключ на консоли был нажат.

Применяется к