0 votes
by (650 points)
edited

Hi, One of our users complains that in a Linux shell (terminalOptions.FunctionKeysMode = FunctionKeysMode.Linux) the key combos Ctrl+Left Arrow and Ctrl+Right Arrow are used to move between words in the command line. Using our application to connect to a remote shell does not send those key combination correctly (He have tried all Function keys mode).

If he hits Ctrl+V, Left Arrow He gets the following output: ^[[D

If he hits Ctrl+V, Ctrl+Left Arrow He gets the following output again: ^[[D but he says that the output should be: ^[[1;5D

I hope that you understand what he means. What should I do to solve this issue?

Regards,

1 Answer

0 votes
by (73.5k points)
edited

You can map keyboard keys like this:

terminal.KeyDown += new KeyEventHandler(terminal_KeyDown);

void terminal_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Control)
    {
        char identifier = ' ';
        switch (e.KeyCode)
        {
            case Keys.Up: identifier = 'A'; break;
            case Keys.Down: identifier = 'B'; break;
            case Keys.Right: identifier = 'C'; break;
            case Keys.Left: identifier = 'D'; break;
        }
        if (identifier != ' ')
        {
            terminal.SendToServer("\x1B[1;5" + identifier);
            e.Handled = true;
            return;
        }
    }
}

The code above sends ^[[1;5D when CTRL+Left Arrow is pressed.

...