ConsoleKey Enum

Definisi

Menentukan kunci standar pada konsol.

public enum class ConsoleKey
public enum ConsoleKey
[System.Serializable]
public enum ConsoleKey
type ConsoleKey = 
[<System.Serializable>]
type ConsoleKey = 
Public Enum ConsoleKey
Warisan
ConsoleKey
Atribut

Bidang

Nama Nilai Deskripsi
None 0
Backspace 8

Kunci BACKSPACE.

Tab 9

Tombol TAB.

Clear 12

Kunci CLEAR.

Enter 13

Tombol ENTER.

Pause 19

Kunci JEDA.

Escape 27

Kunci ESC (ESCAPE).

Spacebar 32

Kunci SPACEBAR.

PageUp 33

Kunci PAGE UP.

PageDown 34

Tombol PAGE DOWN.

End 35

Kunci END.

Home 36

Kunci HOME.

LeftArrow 37

Tombol PANAH KIRI.

UpArrow 38

Tombol PANAH ATAS.

RightArrow 39

Tombol PANAH KANAN.

DownArrow 40

Tombol PANAH BAWAH.

Select 41

Kunci SELECT.

Print 42

Tombol PRINT.

Execute 43

Kunci EXECUTE.

PrintScreen 44

Tombol PRINT SCREEN.

Insert 45

Kunci INS (INSERT).

Delete 46

Kunci DEL (DELETE).

Help 47

Kunci BANTUAN.

D0 48

Kunci 0.

D1 49

Kunci 1.

D2 50

Kunci 2.

D3 51

Kunci 3.

D4 52

Kunci 4.

D5 53

Kunci 5.

D6 54

Kunci 6.

D7 55

Kunci 7.

D8 56

Kunci 8.

D9 57

Kunci 9.

A 65

Kunci A.

B 66

Kunci B.

C 67

Kunci C.

D 68

Kunci D.

E 69

Kunci E.

F 70

Kunci F.

G 71

Kunci G.

H 72

Kunci H.

I 73

Kunci I.

J 74

Kunci J.

K 75

Kunci K.

L 76

Kunci L.

M 77

Kunci M.

N 78

Kunci N.

O 79

Kunci O.

P 80

Kunci P.

Q 81

Kunci Q.

R 82

Kunci R.

S 83

Kunci S.

T 84

Kunci T.

U 85

Kunci U.

V 86

Kunci V.

W 87

Kunci W.

X 88

Kunci X.

Y 89

Kunci Y.

Z 90

Kunci Z.

LeftWindows 91

Kunci logo Windows kiri (Microsoft Keyboard Alami).

RightWindows 92

Kunci logo Windows kanan (Microsoft Keyboard Alami).

Applications 93

Kunci Aplikasi (Microsoft Keyboard Alami).

Sleep 95

Kunci Komputer Tidur.

NumPad0 96

Tombol 0 pada keypad numerik.

NumPad1 97

1 tombol pada keypad numerik.

NumPad2 98

Tombol 2 pada keypad numerik.

NumPad3 99

Tombol 3 pada keypad numerik.

NumPad4 100

Tombol 4 pada keypad numerik.

NumPad5 101

5 tombol pada keypad numerik.

NumPad6 102

Tombol 6 pada keypad numerik.

NumPad7 103

Tombol 7 pada keypad numerik.

NumPad8 104

Tombol 8 pada keypad numerik.

NumPad9 105

Tombol 9 pada keypad numerik.

Multiply 106

Tombol Kalikan (kunci perkalian pada keypad numerik).

Add 107

Tombol Tambahkan (kunci penambahan pada keypad numerik).

Separator 108

Kunci Pemisah.

Subtract 109

Tombol Kurangi (kunci pengurangan pada keypad numerik).

Decimal 110

Kunci Desimal (kunci desimal pada keypad numerik).

Divide 111

Tombol Bagi (kunci pembagian pada keypad numerik).

F1 112

Kunci F1.

F2 113

Kunci F2.

F3 114

Kunci F3.

F4 115

Kunci F4.

F5 116

Kunci F5.

F6 117

Kunci F6.

F7 118

Kunci F7.

F8 119

Kunci F8.

F9 120

Kunci F9.

F10 121

Kunci F10.

F11 122

Kunci F11.

F12 123

Kunci F12.

F13 124

Kunci F13.

F14 125

Kunci F14.

F15 126

Kunci F15.

F16 127

Kunci F16.

F17 128

Kunci F17.

F18 129

Kunci F18.

F19 130

Kunci F19.

F20 131

Kunci F20.

F21 132

Kunci F21.

F22 133

Kunci F22.

F23 134

Kunci F23.

F24 135

Kunci F24.

BrowserBack 166

Kunci Kembali Browser.

BrowserForward 167

Kunci Penerusan Browser.

BrowserRefresh 168

Kunci Refresh Browser.

BrowserStop 169

Tombol Hentikan Browser.

BrowserSearch 170

Kunci Pencarian Browser.

BrowserFavorites 171

Kunci Favorit Browser.

BrowserHome 172

Kunci Beranda Browser.

VolumeMute 173

Tombol Matikan Suara Volume (Microsoft Keyboard Alami).

VolumeDown 174

Tombol Volume Turun (Microsoft Keyboard Alami).

VolumeUp 175

Tombol Volume Naik (Microsoft Keyboard Alami).

MediaNext 176

Kunci Lacak Berikutnya Media.

MediaPrevious 177

Kunci Media Previous Track.

MediaStop 178

Tombol Hentikan Media.

MediaPlay 179

Tombol Media Play/Jeda.

LaunchMail 180

Tombol Mulai Email (Microsoft Keyboard Alami).

LaunchMediaSelect 181

Tombol Pilih Media (Microsoft Keyboard Alami).

LaunchApp1 182

Tombol Mulai Aplikasi 1 (Microsoft Keyboard Alami).

LaunchApp2 183

Tombol Mulai Aplikasi 2 (Microsoft Keyboard Alami).

Oem1 186

Kunci OEM 1 (spesifik OEM).

OemPlus 187

Tombol OEM Plus pada keyboard negara/wilayah mana pun.

OemComma 188

Tombol Koma OEM pada keyboard negara/wilayah mana pun.

OemMinus 189

Tombol OEM Minus pada keyboard negara/wilayah mana pun.

OemPeriod 190

Tombol Periode OEM pada keyboard negara/wilayah mana pun.

Oem2 191

Kunci OEM 2 (spesifik OEM).

Oem3 192

Kunci OEM 3 (spesifik OEM).

Oem4 219

Kunci OEM 4 (spesifik OEM).

Oem5 220

OEM 5 (spesifik OEM).

Oem6 221

Kunci OEM 6 (spesifik OEM).

Oem7 222

Kunci OEM 7 (spesifik OEM).

Oem8 223

Kunci OEM 8 (spesifik OEM).

Oem102 226

Kunci OEM 102 (spesifik OEM).

Process 229

Kunci PROSES IME.

Packet 231

Kunci PACKET (digunakan untuk meneruskan karakter Unicode dengan penekanan tombol).

Attention 246

Kunci ATTN.

CrSel 247

Kunci CRSEL (CURSOR SELECT).

ExSel 248

Kunci EXSEL (EXTEND SELECTION).

EraseEndOfFile 249

Kunci ERASE EOF.

Play 250

Kunci PLAY.

Zoom 251

Tombol ZOOM.

NoName 252

Konstanta yang dicadangkan untuk digunakan di masa mendatang.

Pa1 253

Kunci PA1.

OemClear 254

Kunci CLEAR (spesifik OEM).

Contoh

Contoh berikut menggunakan ConsoleKey enumerasi untuk menunjukkan kepada pengguna kunci mana yang telah ditekan pengguna.

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.

Keterangan

Enumerasi ConsoleKey biasanya digunakan dalam struktur nfo, yang dikembalikan oleh Console.ReadKey metode untuk menunjukkan kunci mana pada konsol yang telah ditekan.

Berlaku untuk