0 votes
by (170 points)

I use the Rebex File Server creating a SSH server.

Would like to intercept functions key. E.g. when I press arrow up I see in putty 'OA' but don't received anything in event ShellCommand.

Can I intercept those function keys?

1 Answer

0 votes
by (73.6k points)
selected by
 
Best answer

Unfortunately, this is not easily possible at the current version.

The Rebex File Server is primary designed for file transfers. The shell support was added to support SCP protocol, its features are limited.

What you can only do is to implement your custom shell by overriding "sh" command. This of course means you have to implement all shell logic, but you receive every single character, so you can react to function keys. It can be done like this:

server.ShellCommand += (s, e) =>
{
    // override "sh", which is default shell command
    if (e.Command == "sh")
    {
        e.Action = (args, console) =>
        {
            while (true)
            {
                // read next character from the terminal console
                var ch = console.ReadChar();
                if (ch == null)
                    break;
                // write character and it's code to terminal console
                console.WriteLine("{0} ({1:X2})", ch < ' ' ? '?' : ch, (int)ch);
            }
            return 0;
        };
    }
};
...