ConsoleKey Enumeration
TOC
Collapse the table of content
Expand the table of content

ConsoleKey Enumeration

 

Specifies the standard keys on a console.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

[SerializableAttribute]
public enum ConsoleKey

Member nameDescription
A

The A key.

Add

The Add key (the addition key on the numeric keypad).

Applications

The Application key (Microsoft Natural Keyboard).

Attention

The ATTN key.

B

The B key.

Backspace

The BACKSPACE key.

BrowserBack

The Browser Back key (Windows 2000 or later).

BrowserFavorites

The Browser Favorites key (Windows 2000 or later).

BrowserForward

The Browser Forward key (Windows 2000 or later).

BrowserHome

The Browser Home key (Windows 2000 or later).

BrowserRefresh

The Browser Refresh key (Windows 2000 or later).

BrowserSearch

The Browser Search key (Windows 2000 or later).

BrowserStop

The Browser Stop key (Windows 2000 or later).

C

The C key.

Clear

The CLEAR key.

CrSel

The CRSEL (CURSOR SELECT) key.

D

The D key.

D0

The 0 key.

D1

The 1 key.

D2

The 2 key.

D3

The 3 key.

D4

The 4 key.

D5

The 5 key.

D6

The 6 key.

D7

The 7 key.

D8

The 8 key.

D9

The 9 key.

Decimal

The Decimal key (the decimal key on the numeric keypad).

Delete

The DEL (DELETE) key.

Divide

The Divide key (the division key on the numeric keypad).

DownArrow

The DOWN ARROW key.

E

The E key.

End

The END key.

Enter

The ENTER key.

EraseEndOfFile

The ERASE EOF key.

Escape

The ESC (ESCAPE) key.

Execute

The EXECUTE key.

ExSel

The EXSEL (EXTEND SELECTION) key.

F

The F key.

F1

The F1 key.

F10

The F10 key.

F11

The F11 key.

F12

The F12 key.

F13

The F13 key.

F14

The F14 key.

F15

The F15 key.

F16

The F16 key.

F17

The F17 key.

F18

The F18 key.

F19

The F19 key.

F2

The F2 key.

F20

The F20 key.

F21

The F21 key.

F22

The F22 key.

F23

The F23 key.

F24

The F24 key.

F3

The F3 key.

F4

The F4 key.

F5

The F5 key.

F6

The F6 key.

F7

The F7 key.

F8

The F8 key.

F9

The F9 key.

G

The G key.

H

The H key.

Help

The HELP key.

Home

The HOME key.

I

The I key.

Insert

The INS (INSERT) key.

J

The J key.

K

The K key.

L

The L key.

LaunchApp1

The Start Application 1 key (Microsoft Natural Keyboard, Windows 2000 or later).

LaunchApp2

The Start Application 2 key (Microsoft Natural Keyboard, Windows 2000 or later).

LaunchMail

The Start Mail key (Microsoft Natural Keyboard, Windows 2000 or later).

LaunchMediaSelect

The Select Media key (Microsoft Natural Keyboard, Windows 2000 or later).

LeftArrow

The LEFT ARROW key.

LeftWindows

The left Windows logo key (Microsoft Natural Keyboard).

M

The M key.

MediaNext

The Media Next Track key (Windows 2000 or later).

MediaPlay

The Media Play/Pause key (Windows 2000 or later).

MediaPrevious

The Media Previous Track key (Windows 2000 or later).

MediaStop

The Media Stop key (Windows 2000 or later).

Multiply

The Multiply key (the multiplication key on the numeric keypad).

N

The N key.

NoName

A constant reserved for future use.

NumPad0

The 0 key on the numeric keypad.

NumPad1

The 1 key on the numeric keypad.

NumPad2

The 2 key on the numeric keypad.

NumPad3

The 3 key on the numeric keypad.

NumPad4

The 4 key on the numeric keypad.

NumPad5

The 5 key on the numeric keypad.

NumPad6

The 6 key on the numeric keypad.

NumPad7

The 7 key on the numeric keypad.

NumPad8

The 8 key on the numeric keypad.

NumPad9

The 9 key on the numeric keypad.

O

The O key.

Oem1

The OEM 1 key (OEM specific).

Oem102

The OEM 102 key (OEM specific).

Oem2

The OEM 2 key (OEM specific).

Oem3

The OEM 3 key (OEM specific).

Oem4

The OEM 4 key (OEM specific).

Oem5

The OEM 5 (OEM specific).

Oem6

The OEM 6 key (OEM specific).

Oem7

The OEM 7 key (OEM specific).

Oem8

The OEM 8 key (OEM specific).

OemClear

The CLEAR key (OEM specific).

OemComma

The OEM Comma key on any country/region keyboard (Windows 2000 or later).

OemMinus

The OEM Minus key on any country/region keyboard (Windows 2000 or later).

OemPeriod

The OEM Period key on any country/region keyboard (Windows 2000 or later).

OemPlus

The OEM Plus key on any country/region keyboard (Windows 2000 or later).

P

The P key.

Pa1

The PA1 key.

Packet

The PACKET key (used to pass Unicode characters with keystrokes).

PageDown

The PAGE DOWN key.

PageUp

The PAGE UP key.

Pause

The PAUSE key.

Play

The PLAY key.

Print

The PRINT key.

PrintScreen

The PRINT SCREEN key.

Process

The IME PROCESS key.

Q

The Q key.

R

The R key.

RightArrow

The RIGHT ARROW key.

RightWindows

The right Windows logo key (Microsoft Natural Keyboard).

S

The S key.

Select

The SELECT key.

Separator

The Separator key.

Sleep

The Computer Sleep key.

Spacebar

The SPACEBAR key.

Subtract

The Subtract key (the subtraction key on the numeric keypad).

T

The T key.

Tab

The TAB key.

U

The U key.

UpArrow

The UP ARROW key.

V

The V key.

VolumeDown

The Volume Down key (Microsoft Natural Keyboard, Windows 2000 or later).

VolumeMute

The Volume Mute key (Microsoft Natural Keyboard, Windows 2000 or later).

VolumeUp

The Volume Up key (Microsoft Natural Keyboard, Windows 2000 or later).

W

The W key.

X

The X key.

Y

The Y key.

Z

The Z key.

Zoom

The ZOOM key.

The ConsoleKey enumeration is typically used in the System.ConsoleKeyInfo structure, which is returned by the Console.ReadKey method to indicate which key on the console has been pressed.

The following example uses the ConsoleKey enumeration to indicate to the user which key the user had pressed.

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 & ConsoleModifiers.Alt) == ConsoleModifiers.Alt) {
            output.Append(", together with " + ConsoleModifiers.Alt.ToString());
            modifiers = true;
         }
         if ((input.Modifiers & ConsoleModifiers.Control) == ConsoleModifiers.Control)
         {
            if (modifiers) {
               output.Append(" and ");
            }   
            else {
               output.Append(", together with ");
               modifiers = true;
            }
            output.Append(ConsoleModifiers.Control.ToString());
         }
         if ((input.Modifiers & ConsoleModifiers.Shift) == 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, 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. 

Universal Windows Platform
Available since 10
.NET Framework
Available since 2.0
Return to top
Show:
© 2016 Microsoft