Export (0) Print
Expand All
Expand Minimize

Keys Enumeration

Specifies key codes and modifiers.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

[<ComVisibleAttribute(true)>]
[<FlagsAttribute>]
[<TypeConverterAttribute(typeof(KeysConverter))>]
type Keys

Member nameDescription
AThe A key.
AddThe add key.
AltThe ALT modifier key.
AppsThe application key (Microsoft Natural Keyboard).
AttnThe ATTN key.
BThe B key.
BackThe BACKSPACE key.
BrowserBackThe browser back key (Windows 2000 or later).
BrowserFavoritesThe browser favorites key (Windows 2000 or later).
BrowserForwardThe browser forward key (Windows 2000 or later).
BrowserHomeThe browser home key (Windows 2000 or later).
BrowserRefreshThe browser refresh key (Windows 2000 or later).
BrowserSearchThe browser search key (Windows 2000 or later).
BrowserStopThe browser stop key (Windows 2000 or later).
CThe C key.
CancelThe CANCEL key.
CapitalThe CAPS LOCK key.
CapsLockThe CAPS LOCK key.
ClearThe CLEAR key.
ControlThe CTRL modifier key.
ControlKeyThe CTRL key.
CrselThe CRSEL key.
DThe D key.
D0The 0 key.
D1The 1 key.
D2The 2 key.
D3The 3 key.
D4The 4 key.
D5The 5 key.
D6The 6 key.
D7The 7 key.
D8The 8 key.
D9The 9 key.
DecimalThe decimal key.
DeleteThe DEL key.
DivideThe divide key.
DownThe DOWN ARROW key.
EThe E key.
EndThe END key.
EnterThe ENTER key.
EraseEofThe ERASE EOF key.
EscapeThe ESC key.
ExecuteThe EXECUTE key.
ExselThe EXSEL key.
FThe F key.
F1The F1 key.
F10The F10 key.
F11The F11 key.
F12The F12 key.
F13The F13 key.
F14The F14 key.
F15The F15 key.
F16The F16 key.
F17The F17 key.
F18The F18 key.
F19The F19 key.
F2The F2 key.
F20The F20 key.
F21The F21 key.
F22The F22 key.
F23The F23 key.
F24The F24 key.
F3The F3 key.
F4The F4 key.
F5The F5 key.
F6The F6 key.
F7The F7 key.
F8The F8 key.
F9The F9 key.
FinalModeThe IME final mode key.
GThe G key.
HThe H key.
HanguelModeThe IME Hanguel mode key. (maintained for compatibility; use HangulMode)
HangulModeThe IME Hangul mode key.
HanjaModeThe IME Hanja mode key.
HelpThe HELP key.
HomeThe HOME key.
IThe I key.
IMEAcceptThe IME accept key, replaces IMEAceept.
IMEAceeptThe IME accept key. Obsolete, use IMEAccept instead.
IMEConvertThe IME convert key.
IMEModeChangeThe IME mode change key.
IMENonconvertThe IME nonconvert key.
InsertThe INS key.
JThe J key.
JunjaModeThe IME Junja mode key.
KThe K key.
KanaModeThe IME Kana mode key.
KanjiModeThe IME Kanji mode key.
KeyCodeThe bitmask to extract a key code from a key value.
LThe L key.
LaunchApplication1The start application one key (Windows 2000 or later).
LaunchApplication2The start application two key (Windows 2000 or later).
LaunchMailThe launch mail key (Windows 2000 or later).
LButtonThe left mouse button.
LControlKeyThe left CTRL key.
LeftThe LEFT ARROW key.
LineFeedThe LINEFEED key.
LMenuThe left ALT key.
LShiftKeyThe left SHIFT key.
LWinThe left Windows logo key (Microsoft Natural Keyboard).
MThe M key.
MButtonThe middle mouse button (three-button mouse).
MediaNextTrackThe media next track key (Windows 2000 or later).
MediaPlayPauseThe media play pause key (Windows 2000 or later).
MediaPreviousTrackThe media previous track key (Windows 2000 or later).
MediaStopThe media Stop key (Windows 2000 or later).
MenuThe ALT key.
ModifiersThe bitmask to extract modifiers from a key value.
MultiplyThe multiply key.
NThe N key.
NextThe PAGE DOWN key.
NoNameA constant reserved for future use.
NoneNo key pressed.
NumLockThe NUM LOCK key.
NumPad0The 0 key on the numeric keypad.
NumPad1The 1 key on the numeric keypad.
NumPad2The 2 key on the numeric keypad.
NumPad3The 3 key on the numeric keypad.
NumPad4The 4 key on the numeric keypad.
NumPad5The 5 key on the numeric keypad.
NumPad6The 6 key on the numeric keypad.
NumPad7The 7 key on the numeric keypad.
NumPad8The 8 key on the numeric keypad.
NumPad9The 9 key on the numeric keypad.
OThe O key.
Oem1The OEM 1 key.
Oem102The OEM 102 key.
Oem2The OEM 2 key.
Oem3The OEM 3 key.
Oem4The OEM 4 key.
Oem5The OEM 5 key.
Oem6The OEM 6 key.
Oem7The OEM 7 key.
Oem8The OEM 8 key.
OemBackslashThe OEM angle bracket or backslash key on the RT 102 key keyboard (Windows 2000 or later).
OemClearThe CLEAR key.
OemCloseBracketsThe OEM close bracket key on a US standard keyboard (Windows 2000 or later).
OemcommaThe OEM comma key on any country/region keyboard (Windows 2000 or later).
OemMinusThe OEM minus key on any country/region keyboard (Windows 2000 or later).
OemOpenBracketsThe OEM open bracket key on a US standard keyboard (Windows 2000 or later).
OemPeriodThe OEM period key on any country/region keyboard (Windows 2000 or later).
OemPipeThe OEM pipe key on a US standard keyboard (Windows 2000 or later).
OemplusThe OEM plus key on any country/region keyboard (Windows 2000 or later).
OemQuestionThe OEM question mark key on a US standard keyboard (Windows 2000 or later).
OemQuotesThe OEM singled/double quote key on a US standard keyboard (Windows 2000 or later).
OemSemicolonThe OEM Semicolon key on a US standard keyboard (Windows 2000 or later).
OemtildeThe OEM tilde key on a US standard keyboard (Windows 2000 or later).
PThe P key.
Pa1The PA1 key.
PacketUsed to pass Unicode characters as if they were keystrokes. The Packet key value is the low word of a 32-bit virtual-key value used for non-keyboard input methods.
PageDownThe PAGE DOWN key.
PageUpThe PAGE UP key.
PauseThe PAUSE key.
PlayThe PLAY key.
PrintThe PRINT key.
PrintScreenThe PRINT SCREEN key.
PriorThe PAGE UP key.
ProcessKeyThe PROCESS KEY key.
QThe Q key.
RThe R key.
RButtonThe right mouse button.
RControlKeyThe right CTRL key.
ReturnThe RETURN key.
RightThe RIGHT ARROW key.
RMenuThe right ALT key.
RShiftKeyThe right SHIFT key.
RWinThe right Windows logo key (Microsoft Natural Keyboard).
SThe S key.
ScrollThe SCROLL LOCK key.
SelectThe SELECT key.
SelectMediaThe select media key (Windows 2000 or later).
SeparatorThe separator key.
ShiftThe SHIFT modifier key.
ShiftKeyThe SHIFT key.
SleepThe computer sleep key.
SnapshotThe PRINT SCREEN key.
SpaceThe SPACEBAR key.
SubtractThe subtract key.
TThe T key.
TabThe TAB key.
UThe U key.
UpThe UP ARROW key.
VThe V key.
VolumeDownThe volume down key (Windows 2000 or later).
VolumeMuteThe volume mute key (Windows 2000 or later).
VolumeUpThe volume up key (Windows 2000 or later).
WThe W key.
XThe X key.
XButton1The first x mouse button (five-button mouse).
XButton2The second x mouse button (five-button mouse).
YThe Y key.
ZThe Z key.
ZoomThe ZOOM key.

The Keys class contains constants for processing keyboard input. The members of the Keys enumeration consist of a key code and a set of modifiers combined into a single integer value. In the Win32 application programming interface (API) a key value has two halves, with the high-order bits containing the key code (which is the same as a Windows virtual key code), and the low-order bits representing key modifiers such as the SHIFT, CONTROL, and ALT keys.

Caution noteCaution

Do not use the values in this enumeration for combined bitwise operations. The values in the enumeration are not mutually exclusive.

NoteNote

This enumeration provides no way to test whether the CAPS LOCK or NUM LOCK keys are currently activated. You can use one of the following techniques to determine if these keys are activated:

  • Call the IsKeyLocked method of the Control class.

  • For finer control, use the Win32 API functions GetKeyState, GetAsyncKeyState, or GetKeyboardState defined in user32.dll, to do this. For more information about calling native functions, see Consuming Unmanaged DLL Functions.

The following table shows the key code values represented by two enumerated values, representing both the general original equipment manufacturer (OEM) keys and the more specific U.S.-keyboard associations.

Hexadecimal value

U.S. keyboard

General OEM

BA

OemSemicolon

Oem1

BF

OemQuestion

Oem2

C0

Oemtilde

Oem3

DB

OemOpenBrackets

Oem4

DC

OemPipe

Oem5

DD

OemCloseBrackets

Oem6

DE

OemQuotes

Oem7

E2

OemBackslash

Oem102

Caution noteCaution

For the .NET Framework 2.0, a member IMEAccept was added that supersedes the previous entry, IMEAceept, which was spelled incorrectly. The older version has been retained for backward compatibility, but it may be deleted in future versions of the .NET Framework

The following code example uses the KeyDown event to determine the type of character entered into the control.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.3, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft