ConsoleKey Enumeration
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Gibt die Standardtasten in einer Konsole an.
public enum class ConsoleKey
[System.Serializable]
public enum ConsoleKey
public enum ConsoleKey
[<System.Serializable>]
type ConsoleKey =
type ConsoleKey =
Public Enum ConsoleKey
- Vererbung
- Attribute
Felder
| Name | Wert | Beschreibung |
|---|---|---|
| Backspace | 8 | RÜCKTASTE. |
| Tab | 9 | TAB-TASTE. |
| Clear | 12 | DIE ENTF-TASTE. |
| Enter | 13 | Die EINGABETASTE. |
| Pause | 19 | PAUSE-TASTE. |
| Escape | 27 | DIE ESC-TASTE (ESCAPE). |
| Spacebar | 32 | LEERTASTE. |
| PageUp | 33 | BILD-AUF-TASTE. |
| PageDown | 34 | BILD-AB-TASTE. |
| End | 35 | ENDE-TASTE. |
| Home | 36 | POS1-TASTE. |
| LeftArrow | 37 | DIE NACH-LINKS-TASTE. |
| UpArrow | 38 | DIE NACH-OBEN-TASTE. |
| RightArrow | 39 | DIE NACH-RECHTS-TASTE. |
| DownArrow | 40 | DIE NACH-UNTEN-TASTE. |
| Select | 41 | Die SELECT-TASTE. |
| 42 | Die DRUCKTASTE. |
|
| Execute | 43 | Die EXECUTE-TASTE. |
| PrintScreen | 44 | DIE DRUCKTASTE. |
| Insert | 45 | DIE INS-TASTE (INSERT). |
| Delete | 46 | ENTF-TASTE (ENTF). |
| Help | 47 | Der HILFE-Schlüssel. |
| D0 | 48 | 0-TASTE. |
| D1 | 49 | 1-TASTE. |
| D2 | 50 | 2-TASTE. |
| D3 | 51 | 3-TASTE. |
| D4 | 52 | 4-TASTE. |
| D5 | 53 | 5-TASTE. |
| D6 | 54 | 6-TASTE. |
| D7 | 55 | 7-TASTE. |
| D8 | 56 | 8-TASTE. |
| D9 | 57 | 9-TASTE. |
| A | 65 | A-TASTE. |
| B | 66 | B-TASTE. |
| C | 67 | C-TASTE. |
| D | 68 | D-TASTE. |
| E | 69 | E-TASTE. |
| F | 70 | F-TASTE. |
| G | 71 | G-TASTE. |
| H | 72 | H-TASTE. |
| I | 73 | I-TASTE. |
| J | 74 | J-TASTE. |
| K | 75 | K-TASTE. |
| L | 76 | L-TASTE. |
| M | 77 | M-TASTE. |
| N | 78 | N-TASTE. |
| O | 79 | O-TASTE. |
| P | 80 | P-TASTE. |
| Q | 81 | Q-TASTE. |
| R | 82 | R-TASTE. |
| S | 83 | S-TASTE. |
| T | 84 | T-TASTE. |
| U | 85 | U-TASTE. |
| V | 86 | V-TASTE. |
| W | 87 | W-TASTE. |
| X | 88 | X-TASTE. |
| Y | 89 | Y-TASTE. |
| Z | 90 | Z-TASTE. |
| LeftWindows | 91 | Die linke Windows Logo-Taste (Microsoft natürliche Tastatur). |
| RightWindows | 92 | Die rechte Windows Logo-Taste (Microsoft natürliche Tastatur). |
| Applications | 93 | Die Anwendungstaste (Microsoft natürliche Tastatur). |
| Sleep | 95 | Die Computer-Energiespartaste. |
| NumPad0 | 96 | Die TASTE 0 auf der Zehnertastatur. |
| NumPad1 | 97 | Die Taste 1 auf der Zehnertastatur. |
| NumPad2 | 98 | Die 2-Taste auf der Zehnertastatur. |
| NumPad3 | 99 | Die 3-TASTE auf der Zehnertastatur. |
| NumPad4 | 100 | Die 4-TASTE auf der Zehnertastatur. |
| NumPad5 | 101 | Die 5-TASTE auf der Zehnertastatur. |
| NumPad6 | 102 | Die 6-TASTE auf der Zehnertastatur. |
| NumPad7 | 103 | Die 7-TASTE auf der Zehnertastatur. |
| NumPad8 | 104 | Die 8-TASTE auf der Zehnertastatur. |
| NumPad9 | 105 | Die 9-TASTE auf der Zehnertastatur. |
| Multiply | 106 | Die Multipliziertaste (multiplizierte Taste auf der Zehnertastatur). |
| Add | 107 | Die Taste "Hinzufügen" (die Zusatztaste auf der Zehnertastatur). |
| Separator | 108 | Die Trenntaste. |
| Subtract | 109 | Die Subtrahieren-Taste (die Subtraktionstaste auf der Zehnertastatur). |
| Decimal | 110 | Die Dezimaltaste (die Dezimaltaste auf der Zehnertastatur). |
| Divide | 111 | Die Trenntaste (die Divisiontaste auf der Zehnertastatur). |
| F1 | 112 | F1-TASTE. |
| F2 | 113 | F2-TASTE. |
| F3 | 114 | F3-TASTE. |
| F4 | 115 | F4-TASTE. |
| F5 | 116 | F5-TASTE. |
| F6 | 117 | F6-TASTE. |
| F7 | 118 | F7-TASTE. |
| F8 | 119 | F8-TASTE. |
| F9 | 120 | F9-TASTE. |
| F10 | 121 | F10-TASTE. |
| F11 | 122 | F11-TASTE. |
| F12 | 123 | F12-TASTE. |
| F13 | 124 | F13-TASTE. |
| F14 | 125 | F14-TASTE. |
| F15 | 126 | F15-TASTE. |
| F16 | 127 | F16-TASTE. |
| F17 | 128 | F17-TASTE. |
| F18 | 129 | F18-TASTE. |
| F19 | 130 | F19-TASTE. |
| F20 | 131 | F20-TASTE. |
| F21 | 132 | F21-TASTE. |
| F22 | 133 | F22-TASTE. |
| F23 | 134 | F23-TASTE. |
| F24 | 135 | F24-TASTE. |
| BrowserBack | 166 | Die RÜCK-TASTE des Browsers. |
| BrowserForward | 167 | Die Vorwärtstaste des Browsers. |
| BrowserRefresh | 168 | Die Browseraktualisierungstaste. |
| BrowserStop | 169 | Die Browser-Stopptaste. |
| BrowserSearch | 170 | Der Browser-Suchschlüssel. |
| BrowserFavorites | 171 | Der Schlüssel "Browserfavoriten". |
| BrowserHome | 172 | Die Starttaste des Browsers. |
| VolumeMute | 173 | Die Taste "Lautstärke stummschalten" (Microsoft natürliche Tastatur). |
| VolumeDown | 174 | Die TASTE "Leiser" (Microsoft natürliche Tastatur). |
| VolumeUp | 175 | Die Lautertaste (Microsoft natürliche Tastatur). |
| MediaNext | 176 | Die Medientaste "Nächster Titel". |
| MediaPrevious | 177 | Die Taste "Vorheriger Titel" für Medien. |
| MediaStop | 178 | Die Medienstopptaste. |
| MediaPlay | 179 | Die Medienwiedergabe-/Pause-Taste. |
| LaunchMail | 180 | Die Taste "E-Mail starten" (Microsoft natürliche Tastatur). |
| LaunchMediaSelect | 181 | Die Medientaste auswählen (Microsoft natürliche Tastatur). |
| LaunchApp1 | 182 | Die Taste "Anwendung starten 1" (Microsoft natürliche Tastatur). |
| LaunchApp2 | 183 | Die Taste "Anwendung starten 2" (Microsoft natürliche Tastatur). |
| Oem1 | 186 | Der OEM 1-Schlüssel (OEM-spezifisch). |
| OemPlus | 187 | Die OEM Plus-Taste auf einer beliebigen Landes-/Regionstastaturen. |
| OemComma | 188 | Die OEM-Kommataste auf einer beliebigen Landes-/Regionstastaturen. |
| OemMinus | 189 | Die OEM-Minustaste auf einer beliebigen Landes-/Regionstastaturen. |
| OemPeriod | 190 | Die OEM-Punkttaste auf einer beliebigen Länder-/Regionstastaturen. |
| Oem2 | 191 | Der OEM 2-Schlüssel (OEM-spezifisch). |
| Oem3 | 192 | Der OEM 3-Schlüssel (OEM-spezifisch). |
| Oem4 | 219 | Der OEM 4-Schlüssel (OEM-spezifisch). |
| Oem5 | 220 | Der OEM 5 (OEM-spezifisch). |
| Oem6 | 221 | Der OEM 6-Schlüssel (OEM-spezifisch). |
| Oem7 | 222 | Der OEM 7-Schlüssel (OEM-spezifisch). |
| Oem8 | 223 | Der OEM 8-Schlüssel (OEM-spezifisch). |
| Oem102 | 226 | Der OEM 102-Schlüssel (OEM-spezifisch). |
| Process | 229 | Der IME PROCESS-Schlüssel. |
| Packet | 231 | Der PACKET-Schlüssel (wird verwendet, um Unicode-Zeichen mit Tastaturanschlägen zu übergeben). |
| Attention | 246 | DIE ATTN-TASTE. |
| CrSel | 247 | DIE CRSEL-TASTE (CURSOR SELECT). |
| ExSel | 248 | Die EXSEL-TASTE (EXTEND SELECTION). |
| EraseEndOfFile | 249 | Die EOF-TASTE LÖSCHEN. |
| Play | 250 | Die PLAY-TASTE. |
| Zoom | 251 | Zoomtaste. |
| NoName | 252 | Eine Konstante, die für die zukünftige Verwendung reserviert ist. |
| Pa1 | 253 | Pa1-Taste. |
| OemClear | 254 | Die CLEAR-Taste (OEM-spezifisch). |
Beispiele
Im folgenden Beispiel wird die ConsoleKey Enumeration verwendet, um dem Benutzer anzugeben, welche Taste der Benutzer gedrückt hat.
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.
Hinweise
Die ConsoleKey Enumeration wird in der Regel in der nfo-Struktur verwendet, die von der Console.ReadKey Methode zurückgegeben wird, um anzugeben, welche Taste auf der Konsole gedrückt wurde.