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

Enter キー。

Pause 19

Pause キー

Escape 27

ESC (ESCAPE) キー。

Spacebar 32

Space キー

PageUp 33

PageUp キー

PageDown 34

PageDown キー

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

印刷画面キー。

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

Decimal キー (テンキーの 10 進キー)。

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

Browser Stop キー。

BrowserSearch 170

ブラウザー検索キー。

BrowserFavorites 171

ブラウザーのお気に入りキー。

BrowserHome 172

ブラウザーのホーム キー。

VolumeMute 173

音量ミュート キー (Microsoftナチュラル キーボード)。

VolumeDown 174

音量を下げるキー (Microsoftナチュラル キーボード)。

VolumeUp 175

音量を上げるキー (Microsoftナチュラル キーボード)。

MediaNext 176

Media Next Track キー。

MediaPrevious 177

メディアの前のトラック キー。

MediaStop 178

Media Stop キー。

MediaPlay 179

メディア再生/一時停止キー。

LaunchMail 180

メールの開始キー (Microsoftナチュラル キーボード)。

LaunchMediaSelect 181

メディアの選択キー (Microsoftナチュラル キーボード)。

LaunchApp1 182

アプリケーションの開始 1 キー (Microsoftナチュラル キーボード)。

LaunchApp2 183

アプリケーションの開始 2 キー (Microsoftナチュラル キーボード)。

Oem1 186

OEM 1 キー (OEM 固有)。

OemPlus 187

任意の国/地域キーボードの OEM Plus キー。

OemComma 188

任意の国/地域のキーボードの OEM コンマ キー。

OemMinus 189

任意の国/地域キーボードの OEM マイナス キー。

OemPeriod 190

任意の国/地域のキーボードの 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 固有)。

Oem102 226

OEM 102 キー (OEM 固有)。

Process 229

IME PROCESS キー。

Packet 231

PACKET キー (キーストロークで Unicode 文字を渡すために使用されます)。

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 キー (OEM 固有)。

次の例では、 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 メソッドによって返されます。

適用対象