Table of Contents

Enum KeyCode

Namespace
Terminal.Gui
Assembly
Terminal.Gui.dll

The KeyCode enumeration encodes key information from IConsoleDrivers and provides a consistent way for application code to specify keys and receive key events.

The Key class provides a higher-level abstraction, with helper methods and properties for common operations. For example, IsAlt and IsCtrl provide a convenient way to check whether the Alt or Ctrl modifier keys were pressed when a key was pressed.

[Flags]
public enum KeyCode : uint

Fields

A = 65

The key code for the A key

AltMask = 2147483648

When this value is set, the Key encodes the sequence Alt-KeyValue. The actual value must be extracted by removing the AltMask.

B = 66

The key code for the B key

Backspace = 8

Backspace key.

C = 67

The key code for the C key

CharMask = 1048575

Mask that indicates that the key is a unicode codepoint. Values outside this range indicate the key has shift modifiers or is a special key like function keys, arrows keys and so on.

Clear = 12

The key code for the clear key.

CtrlMask = 1073741824

When this value is set, the Key encodes the sequence Ctrl-KeyValue. The actual value must be extracted by removing the CtrlMask.

CursorDown = 1114151

Cursor down key.

CursorLeft = 1114148

Cursor left key.

CursorRight = 1114150

Cursor right key.

CursorUp = 1114149

Cursor up key

D = 68

The key code for the D key

D0 = 48

Digit 0.

D1 = 49

Digit 1.

D2 = 50

Digit 2.

D3 = 51

Digit 3.

D4 = 52

Digit 4.

D5 = 53

Digit 5.

D6 = 54

Digit 6.

D7 = 55

Digit 7.

D8 = Backspace | D0

Digit 8.

D9 = 57

Digit 9.

Delete = 1114157

Delete (DEL) key.

E = 69

The key code for the E key

End = 1114146

End key.

Enter = 13

The key code for the return key.

Esc = 27

The key code for the escape key.

F = 70

The key code for the F key

F1 = B | Delete

F1 key.

F10 = Backspace | F2

F10 key.

F11 = 1114233

F11 key.

F12 = 1114234

F12 key.

F13 = 1114235

F13 key.

F14 = 1114236

F14 key.

F15 = 1114237

F15 key.

F16 = 1114238

F16 key.

F17 = 1114239

F17 key.

F18 = 1114240

F18 key.

F19 = 1114241

F19 key.

F2 = P | PageUp

F2 key.

F20 = 1114242

F20 key.

F21 = 1114243

F21 key.

F22 = 1114244

F22 key.

F23 = 1114245

F23 key.

F24 = 1114246

F24 key.

F3 = 1114225

F3 key.

F4 = 1114226

F4 key.

F5 = 1114227

F5 key.

F6 = 1114228

F6 key.

F7 = 1114229

F7 key.

F8 = 1114230

F8 key.

F9 = 1114231

F9 key.

G = 71

The key code for the G key

H = 72

The key code for the H key

Home = 1114147

Home key.

I = 73

The key code for the I key

Insert = Backspace | CursorLeft

Insert (INS) key.

J = 74

The key code for the J key

K = 75

The key code for the K key

L = 76

The key code for the L key

M = 77

The key code for the M key

MaxCodePoint = 1114111

The maximum Unicode codepoint value. Used to encode the non-alphanumeric control keys.

N = 78

The key code for the N key

Null = 0

The key code representing an invalid or empty key.

O = 79

The key code for the O key

P = 80

The key code for the P key

PageDown = 1114145

Page Down key.

PageUp = 1114144

Page Up key.

PrintScreen = Backspace | Home

Print screen character key.

Q = 81

The key code for the Q key

R = 82

The key code for the R key

S = 83

The key code for the S key

ShiftMask = 268435456

When this value is set, the Key encodes the sequence Shift-KeyValue. The actual value must be extracted by removing the ShiftMask.

Space = 32

The key code for the space bar key.

SpecialMask = 4293918720

If the SpecialMask is set, then the value is that of the special mask, otherwise, the value is in the lower bits (as extracted by CharMask).

T = 84

The key code for the T key

Tab = 9

The key code for the tab key (forwards tab key).

U = 85

The key code for the U key

V = 86

The key code for the V key

W = 87

The key code for the W key

X = Backspace | P

The key code for the X key

Y = 89

The key code for the Y key

Z = 90

The key code for the Z key

Remarks

Lowercase alpha keys are encoded as values between 65 and 90 corresponding to the un-shifted A to Z keys on a keyboard. Enum values are provided for these (e.g. A, B, etc.). Even though the values are the same as the ASCII values for uppercase characters, these enum values represent *lowercase*, un-shifted characters.

Numeric keys are the values between 48 and 57 corresponding to 0 to 9 (e.g. D0, D1, etc.).

The shift modifiers (ShiftMask, CtrlMask, and AltMask) can be combined (with logical or) with the other key codes to represent shifted keys. For example, the A enum value represents the un-shifted 'a' key, while ShiftMask | A represents the 'A' key (shifted 'a' key). Likewise, AltMask | A represents the 'Alt+A' key combination.

All other keys that produce a printable character are encoded as the Unicode value of the character. For example, the KeyCode for the '!' character is 33, which is the Unicode value for '!'. Likewise, `â` is 226, `Â` is 194, etc.

If the SpecialMask is set, then the value is that of the special mask, otherwise, the value is the one of the lower bits (as extracted by CharMask).