ConsoleKey Enumerazione

Definizione

Specifica le chiavi standard in una console.

public enum class ConsoleKey
public enum ConsoleKey
[System.Serializable]
public enum ConsoleKey
type ConsoleKey = 
[<System.Serializable>]
type ConsoleKey = 
Public Enum ConsoleKey
Ereditarietà
ConsoleKey
Attributi

Campi

Nome Valore Descrizione
None 0
Backspace 8

Tasto BACKSPACE.

Tab 9

Tasto TAB.

Clear 12

Tasto CLEAR.

Enter 13

Tasto INVIO.

Pause 19

Tasto PAUSE.

Escape 27

Tasto ESC (ESCAPE).

Spacebar 32

Tasto BARRA SPAZIATRICE.

PageUp 33

Tasto PAGE UP.

PageDown 34

Tasto PAGINA GIÙ.

End 35

Tasto END.

Home 36

Tasto HOME.

LeftArrow 37

Tasto FRECCIA SINISTRA.

UpArrow 38

Tasto FRECCIA SU.

RightArrow 39

Tasto FRECCIA DESTRA.

DownArrow 40

Tasto FRECCIA GIÙ.

Select 41

Tasto SELECT.

Print 42

Tasto PRINT.

Execute 43

Tasto EXECUTE.

PrintScreen 44

Tasto PRINT SCREEN.

Insert 45

Tasto INS (INSERT).

Delete 46

Tasto CANC (CANC).

Help 47

Tasto HELP.

D0 48

Tasto 0.

D1 49

Tasto 1.

D2 50

Tasto 2.

D3 51

Tasto 3.

D4 52

Tasto 4.

D5 53

Tasto 5.

D6 54

Tasto 6.

D7 55

Tasto 7.

D8 56

Tasto 8.

D9 57

Tasto 9.

A 65

Tasto A.

B 66

Tasto B.

C 67

Tasto C.

D 68

Tasto D.

E 69

Tasto E.

F 70

Tasto F.

G 71

Tasto G.

H 72

Tasto H.

I 73

La chiave io.

J 74

Tasto J.

K 75

Tasto K.

L 76

Tasto L.

M 77

Tasto M.

N 78

Tasto N.

O 79

Tasto O.

P 80

Tasto P.

Q 81

Tasto Q.

R 82

Tasto R.

S 83

Tasto S.

T 84

Tasto T.

U 85

Tasto U.

V 86

Tasto V.

W 87

Tasto W.

X 88

Tasto X.

Y 89

Tasto Y.

Z 90

Tasto Z.

LeftWindows 91

Tasto logo Windows sinistro (Microsoft tastiera naturale).

RightWindows 92

Tasto logo Windows destro (Microsoft tastiera naturale).

Applications 93

Tasto applicazione (Microsoft tastiera naturale).

Sleep 95

Tasto Sospensione computer.

NumPad0 96

Tasto 0 sul tastierino numerico.

NumPad1 97

Tasto 1 sul tastierino numerico.

NumPad2 98

Tasto 2 sul tastierino numerico.

NumPad3 99

Tasto 3 sul tastierino numerico.

NumPad4 100

Tasto 4 sul tastierino numerico.

NumPad5 101

Tasto 5 sul tastierino numerico.

NumPad6 102

Tasto 6 sul tastierino numerico.

NumPad7 103

Tasto 7 sul tastierino numerico.

NumPad8 104

Tasto 8 sul tastierino numerico.

NumPad9 105

Tasto 9 sul tastierino numerico.

Multiply 106

Tasto Moltiplica (tasto di moltiplicazione sul tastierino numerico).

Add 107

Tasto Aggiungi (tasto di addizione sul tastierino numerico).

Separator 108

Tasto separatore.

Subtract 109

Tasto Sottrazione (tasto di sottrazione sul tastierino numerico).

Decimal 110

Tasto Decimale (tasto decimale sul tastierino numerico).

Divide 111

Tasto di divisione (tasto di divisione sul tastierino numerico).

F1 112

Tasto F1.

F2 113

Tasto F2.

F3 114

Tasto F3.

F4 115

Tasto F4.

F5 116

Tasto F5.

F6 117

Tasto F6.

F7 118

Tasto F7.

F8 119

Tasto F8.

F9 120

Tasto F9.

F10 121

Tasto F10.

F11 122

Tasto F11.

F12 123

Tasto F12.

F13 124

Tasto F13.

F14 125

Tasto F14.

F15 126

Tasto F15.

F16 127

Tasto F16.

F17 128

Tasto F17.

F18 129

Tasto F18.

F19 130

Tasto F19.

F20 131

Tasto F20.

F21 132

Tasto F21.

F22 133

Tasto F22.

F23 134

Tasto F23.

F24 135

Tasto F24.

BrowserBack 166

Tasto Indietro del browser.

BrowserForward 167

Tasto Di inoltro del browser.

BrowserRefresh 168

Tasto di aggiornamento del browser.

BrowserStop 169

Tasto di arresto del browser.

BrowserSearch 170

Chiave di ricerca del browser.

BrowserFavorites 171

Tasto Preferiti del browser.

BrowserHome 172

Tasto Home del browser.

VolumeMute 173

Tasto di disattivazione del volume (Microsoft tastiera naturale).

VolumeDown 174

Tasto di riduzione del volume (Microsoft tastiera naturale).

VolumeUp 175

Tasto di aumento del volume (Microsoft tastiera naturale).

MediaNext 176

Tasto Media Next Track.

MediaPrevious 177

Tasto Media Previous Track.The Media Previous Track key.

MediaStop 178

Tasto di arresto multimediale.

MediaPlay 179

Tasto Media Play/Pause.

LaunchMail 180

Tasto Start Mail (Microsoft tastiera naturale).

LaunchMediaSelect 181

Tasto Seleziona supporto (Microsoft tastiera naturale).

LaunchApp1 182

Tasto Start Application 1 (Microsoft Natural Keyboard).

LaunchApp2 183

Tasto Start Application 2 (Microsoft Natural Keyboard).

Oem1 186

Chiave OEM 1 (specifica OEM).

OemPlus 187

Tasto OEM Plus su qualsiasi tastiera paese/area geografica.

OemComma 188

Tasto virgola OEM in qualsiasi tastiera paese/area geografica.

OemMinus 189

Tasto MENO OEM in qualsiasi tastiera paese/area geografica.

OemPeriod 190

Tasto Periodo OEM in qualsiasi tastiera paese/area geografica.

Oem2 191

Chiave OEM 2 (specifica OEM).

Oem3 192

Chiave OEM 3 (specifica OEM).

Oem4 219

Chiave OEM 4 (specifica OEM).

Oem5 220

OEM 5 (specifico dell'OEM).

Oem6 221

Chiave OEM 6 (specifica OEM).

Oem7 222

Chiave OEM 7 (specifica OEM).

Oem8 223

Chiave OEM 8 (specifica OEM).

Oem102 226

Chiave OEM 102 (specifica OEM).

Process 229

Tasto PROCESSO IME.

Packet 231

Chiave PACKET (usata per passare caratteri Unicode con sequenze di tasti).

Attention 246

Tasto ATTN.

CrSel 247

Tasto CRSEL (CURSOR SELECT).

ExSel 248

Tasto EXSEL (EXTEND SELECTION).

EraseEndOfFile 249

Tasto ERASE EOF.

Play 250

Tasto PLAY.

Zoom 251

Tasto ZOOM.

NoName 252

Costante riservata per uso futuro.

Pa1 253

Tasto PA1.

OemClear 254

Chiave CLEAR (specifica OEM).

Esempio

Nell'esempio seguente viene utilizzata l'enumerazione ConsoleKey per indicare all'utente quale tasto l'utente aveva premuto.

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.

Commenti

L'enumerazione ConsoleKey viene in genere utilizzata nella struttura nfo, restituita dal Console.ReadKey metodo per indicare quale tasto nella console è stato premuto.

Si applica a