0 votes
by (160 points)
edited

Using the VirtualTerminal.SendToServer sub is there any way to send linux encoded function keys instead of sending the windows encoding as a string? Or perhaps another method for sending it as a virtual key?

1 Answer

+1 vote
by (63.4k points)
edited

To send function key recognizable by the remote end you can use the SendToServer(ConsoleKeyInfo) method with FunctionKeysMode set apropriately. Please note that there is a lot of function keys mode (in real word), you have to choose correct one for your particular server.

// send function key F10 using standard predefined Linux convetions
virtualTerminal.Options.FunctionKeysMode = FunctionKeysMode.Linux;
virtualTerminal.SendToServer(new ConsoleKeyInfo('\0', ConsoleKey.F10, false, false, false));

To send text encoded with your preferred encoding, you have to set the Options.Encoding property.

// send some text encoded by specific encoding (new line seqence set to <CR> instead of <CR><LF>)
virtualTerminal.Options.Encoding = System.Text.Encoding.GetEncoding("requested encoding name or codepage");
virtualTerminal.Options.NewLineSequence = NewLineSequence.CR;
virtualTerminal.SendToServer("some text");

Finally, you are able to send raw bytes to the server directly.

// prepare the data
byte[] rawData = new byte[4];
// ...
// send bytes directly to the server
virtualTerminal.SendToServer(rawData, 0, rawData.Length);
...