ConsoleKey Énumération

Définition

Spécifie les clés standard sur une console.

public enum class ConsoleKey
public enum ConsoleKey
[System.Serializable]
public enum ConsoleKey
type ConsoleKey = 
[<System.Serializable>]
type ConsoleKey = 
Public Enum ConsoleKey
Héritage
ConsoleKey
Attributs

Champs

Nom Valeur Description
None 0
Backspace 8

La touche RET.ARR.

Tab 9

La touche Tab.

Clear 12

Touche CLEAR.

Enter 13

Touche ENTRÉE.

Pause 19

La touche Pause.

Escape 27

Touche ÉCHAP (ESCAPE).

Spacebar 32

La barre d'espace.

PageUp 33

La touche Page précédente.

PageDown 34

La touche Page suivante.

End 35

La touche Fin.

Home 36

La touche Origine.

LeftArrow 37

Touche de direction gauche.

UpArrow 38

Flèche vers le haut.

RightArrow 39

Flèche droite.

DownArrow 40

Flèche bas.

Select 41

Touche SELECT.

Print 42

Touche PRINT.

Execute 43

Clé EXECUTE.

PrintScreen 44

Touche ÉCRAN D’IMPRESSION.

Insert 45

Touche INS (INSERT).

Delete 46

Touche DEL (DELETE).

Help 47

Clé HELP.

D0 48

La touche 0.

D1 49

La touche 1.

D2 50

La touche 2.

D3 51

La touche 3.

D4 52

La touche 4.

D5 53

La touche 5.

D6 54

La touche 6.

D7 55

La touche 7.

D8 56

La touche 8.

D9 57

La touche 9.

A 65

La touche A.

B 66

La touche 0.

C 67

La touche C.

D 68

La touche D.

E 69

La touche E.

F 70

La touche F.

G 71

La touche G.

H 72

La touche H.

I 73

La touche I.

J 74

La touche J.

K 75

La touche K.

L 76

La touche L.

M 77

La touche M.

N 78

La touche N.

O 79

La touche O.

P 80

La touche P.

Q 81

La touche Q.

R 82

La touche R.

S 83

La touche S.

T 84

La touche T.

U 85

La touche U.

V 86

La touche V.

W 87

La touche W.

X 88

La touche X.

Y 89

La touche Y.

Z 90

La touche Z.

LeftWindows 91

Touche de logo Windows gauche (Microsoft Clavier naturel).

RightWindows 92

Touche de logo Windows droite (Microsoft Clavier naturel).

Applications 93

Touche Application (Microsoft Clavier naturel).

Sleep 95

Touche veille de l’ordinateur.

NumPad0 96

Touche 0 sur le pavé numérique.

NumPad1 97

Touche 1 sur le pavé numérique.

NumPad2 98

Touche 2 sur le pavé numérique.

NumPad3 99

Touche 3 sur le pavé numérique.

NumPad4 100

Touche 4 sur le pavé numérique.

NumPad5 101

Touche 5 sur le pavé numérique.

NumPad6 102

Touche 6 sur le pavé numérique.

NumPad7 103

Touche 7 sur le pavé numérique.

NumPad8 104

Touche 8 sur le pavé numérique.

NumPad9 105

Touche 9 sur le pavé numérique.

Multiply 106

Touche Multiplier (la touche de multiplication sur le pavé numérique).

Add 107

Touche Ajouter (touche d’ajout sur le pavé numérique).

Separator 108

Clé de séparateur.

Subtract 109

Touche Soustraire (la touche de soustraction sur le pavé numérique).

Decimal 110

Touche décimale (la touche décimale sur le pavé numérique).

Divide 111

Touche Diviser (la touche de division sur le pavé numérique).

F1 112

La touche F1.

F2 113

La touche F2.

F3 114

La touche F3.

F4 115

La touche F4.

F5 116

La touche F5.

F6 117

La touche F6.

F7 118

La touche F7.

F8 119

La touche F8.

F9 120

La touche F9.

F10 121

La touche F10.

F11 122

La touche F11.

F12 123

La touche F12.

F13 124

La touche F13.

F14 125

La touche F14.

F15 126

La touche F15.

F16 127

La touche F16.

F17 128

Touche F17.

F18 129

Touche F18.

F19 130

Touche F19.

F20 131

Touche F20.

F21 132

Touche F21.

F22 133

Touche F22.

F23 134

Touche F23.

F24 135

Touche F24.

BrowserBack 166

Touche Précédent du navigateur.

BrowserForward 167

Touche Transférer du navigateur.

BrowserRefresh 168

Touche d’actualisation du navigateur.

BrowserStop 169

Touche d’arrêt du navigateur.

BrowserSearch 170

Touche de recherche du navigateur.

BrowserFavorites 171

Touche Favoris du navigateur.

BrowserHome 172

Touche d’accueil du navigateur.

VolumeMute 173

Touche de désactivation du volume (Microsoft clavier naturel).

VolumeDown 174

Touche Volume Down (Microsoft Clavier naturel).

VolumeUp 175

Touche volume vers le haut (Microsoft clavier naturel).

MediaNext 176

Touche de suivi suivant du média.

MediaPrevious 177

Clé de suivi précédente du média.

MediaStop 178

Touche d’arrêt du média.

MediaPlay 179

Touche lecture/pause du média.

LaunchMail 180

Touche Démarrer la messagerie (Microsoft Clavier naturel).

LaunchMediaSelect 181

Touche Sélectionner un média (Microsoft clavier naturel).

LaunchApp1 182

Touche Démarrer l’application 1 (Microsoft clavier naturel).

LaunchApp2 183

Touche Démarrer l’application 2 (Microsoft clavier naturel).

Oem1 186

Clé OEM 1 (spécifique à OEM).

OemPlus 187

Touche OEM Plus sur n’importe quel clavier pays/région.

OemComma 188

Touche de virgule OEM sur n’importe quel clavier pays/région.

OemMinus 189

Touche OEM Moins sur n’importe quel clavier pays/région.

OemPeriod 190

Touche de période OEM sur n’importe quel clavier pays/région.

Oem2 191

Clé OEM 2 (spécifique à l’OEM).

Oem3 192

Clé OEM 3 (spécifique à OEM).

Oem4 219

Clé OEM 4 (spécifique à l’OEM).

Oem5 220

Oem 5 (spécifique à l’OEM).

Oem6 221

Clé OEM 6 (spécifique à OEM).

Oem7 222

Clé OEM 7 (spécifique à l’OEM).

Oem8 223

Clé OEM 8 (spécifique à OEM).

Oem102 226

Clé OEM 102 (spécifique à l’OEM).

Process 229

Clé DE PROCESSUS IME.

Packet 231

Clé PACKET (utilisée pour passer des caractères Unicode avec des séquences de touches).

Attention 246

Clé ATTN.

CrSel 247

Touche CRSEL (CURSOR SELECT).

ExSel 248

Touche EXSEL (EXTEND SELECTION).

EraseEndOfFile 249

Touche EOF ERASE.

Play 250

Touche PLAY.

Zoom 251

Touche ZOOM.

NoName 252

Constante réservée à une utilisation ultérieure.

Pa1 253

Touche PA1.

OemClear 254

Clé CLEAR (spécifique à l’OEM).

Exemples

L’exemple suivant utilise l’énumération ConsoleKey pour indiquer à l’utilisateur quelle touche l’utilisateur a appuyé.

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.

Remarques

L’énumération ConsoleKey est généralement utilisée dans la structure nfo, qui est retournée par la Console.ReadKey méthode pour indiquer quelle touche sur la console a été enfoncée.

S’applique à