ConsoleKey Enumeration

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

Specifies the console keys.

Members

Backspace

The value is 8.

Specifies the backspace key.

Tab

The value is 9.

Specifies the tab key.

Enter

The value is 13.

Specifies the enter key.

Escape

The value is 27.

Specifies the escape key.

Spacebar

The value is 32.

Specifies the spacebar.

PageUp

The value is 33.

Specifies the PAGE UP key.

PageDown

The value is 34.

Specifies the PAGE DOWN key.

End

The value is 35.

Specifies the END key.

Home

The value is 36.

Specifies the HOME key.

LeftArrow

The value is 37.

Specifies the left arrow key.

UpArrow

The value is 38.

Specifies the UP ARROW key.

RightArrow

The value is 39.

Specifies the right arrow key.

DownArrow

The value is 40.

Specifies the DOWN ARROW key.

Insert

The value is 45.

Specifies the INSERT key.

Delete

The value is 46.

Specifies the DELETE key.

D0

The value is 48.

Specifies the 0 key.

D1

The value is 49.

Specifies the 1 key.

D2

The value is 50.

Specifies the 2 key.

D3

The value is 51.

Specifies the 3 key.

D4

The value is 52.

Specifies the 4 key.

D5

The value is 53.

Specifies the 5 key.

D6

The value is 54.

Specifies the 6 key.

D7

The value is 55.

Specifies the 7 key.

D8

The value is 56.

Specifies the 8 key.

D9

The value is 57.

Specifies the 9 key.

A

The value is 65.

Specifies the A key.

B

The value is 66.

Specifies the B key.

C

The value is 67.

Specifies the C key.

D

The value is 68.

Specifies the D key.

E

The value is 69.

Specifies the E key.

F

The value is 70.

Specifies the F key.

G

The value is 71.

Specifies the G key.

H

The value is 72.

Specifies the H key.

I

The value is 73.

Specifies the I key.

J

The value is 74.

Specifies the J key.

K

The value is 75.

Specifies the K key.

L

The value is 76.

Specifies the L key.

M

The value is 77.

Specifies the M key.

N

The value is 78.

Specifies the N key.

O

The value is 79.

Specifies the O key.

P

The value is 80.

Specifies the P key.

Q

The value is 81.

Specifies the Q key.

R

The value is 82.

Specifies the R key.

S

The value is 83.

Specifies the S key.

T

The value is 84.

Specifies the T key.

U

The value is 85.

Specifies the U key.

V

The value is 86.

Specifies the V key.

W

The value is 87.

Specifies the W key.

X

The value is 88.

Specifies the X key.

Y

The value is 89.

Specifies the Y key.

Z

The value is 90.

Specifies the Z key.

LeftWindowKey

The value is 91.

Specifies the left Windows key.

RightWindowKey

The value is 92.

Specifies the right Windows key.

ApplicationKey

The value is 93.

Specifies the Application key.

Sleep

The value is 95.

Specifies the Sleep key.

NumPad0

The value is 96.

Specifies the numeric keypad 0 key.

NumPad1

The value is 97.

Specifies the numeric keypad 1 key.

NumPad2

The value is 98.

Specifies the numeric keypad 2 key.

NumPad3

The value is 99.

Specifies the numeric keypad 3 key.

NumPad4

The value is 100.

Specifies the numeric keypad 4 key.

NumPad5

The value is 101.

Specifies the numeric keypad 5 key.

NumPad6

The value is 102.

Specifies the numeric keypad 6 key.

NumPad7

The value is 103.

Specifies the numeric keypad 7 key.

NumPad8

The value is 104.

Specifies the numeric keypad 8 key.

NumPad9

The value is 105.

Specifies the numeric keypad 9 key.

Multiply

The value is 106.

Specifies the multiplication key on the numeric keypad.

Add

The value is 107.

Specifies the addition key on the numeric keypad.

Subtract

The value is 109.

Specifies the subtraction key on the numeric keypad.

Decimal

The value is 110.

Specifies the decimal key on the numeric keypad.

Divide

The value is 111.

Specifies the division key on the numeric keypad.

F1

The value is 112.

Specifies the F1 key.

F2

The value is 113.

Specifies the F2 key.

F3

The value is 114.

Specifies the F3 key.

F4

The value is 115.

Specifies the F4 key.

F5

The value is 116.

Specifies the F5 key.

F6

The value is 117.

Specifies the F6 key.

F7

The value is 118.

Specifies the F7 key.

F8

The value is 119.

Specifies the F8 key.

F9

The value is 120.

Specifies the F9 key.

F10

The value is 121.

Specifies the F10 key.

F11

The value is 122.

Specifies the F11 key.

F12

The value is 123.

Specifies the F12 key.

F13

The value is 124.

Specifies the F13 key.

F14

The value is 125.

Specifies the F14 key.

F15

The value is 126.

Specifies the F15 key.

F16

The value is 127.

Specifies the F16 key.

NumLock

The value is 144.

Specifies the NUM LOCK key.

ScrollLock

The value is 145.

Specifies the SCROLL LOCK key.

LeftShift

The value is 160.

Specifies the left SHIFT key.

RightShift

The value is 161.

Specifies the right SHIFT key.

LeftControl

The value is 162.

Specifies the left CTRL key.

RightControl

The value is 163.

Specifies the right CTRL key.

LeftAlt

The value is 164.

Specifies the left ALT key.

RightAlt

The value is 165.

Specifies the right ALT key.

BrowserBack

The value is 166.

Specifies the browser back key.

BrowserForward

The value is 167.

Specifies the browser forward key.

BrowserRefresh

The value is 168.

Specifies the browser refresh key.

BrowserStop

The value is 169.

Specifies the browser stop key.

BrowserSearch

The value is 170.

Specifies the browser search key.

BrowserFavorites

The value is 171.

Specifies the browser favorites key.

BrowserHome

The value is 172.

Specifies the browser home key.

VolumeMute

The value is 173.

Specifies the volume mute key.

VolumeDown

The value is 174.

Specifies the volume down key.

VolumeUp

The value is 175.

Specifies the volume up key.

MediaNextTrack

The value is 176.

Specifies the next track media key.

MediaPreviousTrack

The value is 177.

Specifies the previous track media key.

MediaStop

The value is 178.

Specifies the stop media key.

MediaPlayPause

The value is 179.

Specifies the play/pause media key.

LaunchMail

The value is 180.

Specifies the launch mail key.

LaunchApplication1

The value is 181.

Specifies the launch application 1 key.

LaunchApplication2

The value is 182.

Specifies the launch application 2 key.

OemSemicolon

The value is 186.

The OEM Semicolon key.

OemPlus

The value is 187.

The OEM Plus key.

OemComma

The value is 188.

The OEM Comma key.

OemMinus

The value is 189.

The OEM Minus key.

OemPeriod

The value is 190.

The OEM Period key.

OemQuestion

The value is 191.

The OEM Question key.

OemTilde

The value is 192.

The OEM Tilde key.

OemOpenBrackets

The value is 219.

The OEM Open Brackets key.

OemPipe

The value is 220.

The OEM Pipe key.

OemCloseBrackets

The value is 221.

The OEM Close Brackets key.

OemQuotes

The value is 222.

The OEM Quotes key.

OemBackslash

The value is 226.

The OEM Backslash key.

ProcessKey

The value is 229.

The Process key.

ImeConvert

The value is 28.

The IME Convert key.

ImeNonConvert

The value is 29.

The IME Non-convert key.

DbeReplace

The value is 30.

The DBE Replace key.

DbeDbcchar

The value is 31.

The DBE DBC Char key.

Remarks

The ConsoleKey enumeration is used to identify keys on the keyboard. It is often used in conjunction with the ConsoleKeyInfo structure, which represents a combination of a console key and modifier keys (like SHIFT, CTRL, and ALT).

Example


using System;

public class Example
{
    public static void Main()
    {
        Console.WriteLine("Press any key (or Escape to exit)...");
        
        ConsoleKeyInfo keyInfo = Console.ReadKey(true); // true to not display the key
        
        if (keyInfo.Key == ConsoleKey.Escape)
        {
            Console.WriteLine("\nEscape key pressed. Exiting.");
        }
        else
        {
            Console.WriteLine($"\nYou pressed: {keyInfo.Key} (Modifiers: {keyInfo.Modifiers})");
        }
    }
}