Table of Contents

Method Encode

Namespace
Terminal.Gui.Drivers
Assembly
Terminal.Gui.dll

Encode(Key)

Converts a Key to its ANSI escape sequence representation or character.

public static string Encode(Key key)

Parameters

key Key

The key to encode.

Returns

string

An ANSI escape sequence string for special keys (arrows, function keys, etc.), or a character string for regular characters.

Remarks

For special keys (arrows, function keys, etc.), this returns the appropriate ANSI escape sequence. For regular characters, it returns the character itself.

Alt combinations are represented by prefixing the character/sequence with ESC. Ctrl combinations for letters A-Z are represented as ASCII control codes (0x01-0x1A). Shift affects letter case but not control key behavior.

Note: Certain modifier combinations cannot be represented in ANSI (e.g., Ctrl+Shift combinations produce the same control code as Ctrl alone).