using Rebex.Net;

Welcome to using Rebex.Net; Sign in | Help
in Search

Using Rebex.Net

News and announcements about Rebex.NET components

HOWTO: Simulate Ctrl+C programatically in SSH or Telnet

In some applications written using Rebex SSH Shell or Rebex Telnet that utilize a terminal emulation or virtual terminal, it might be useful to be able to send Ctrl+C sequence programatically. And although this is easy when you know how Ctrl+C actually behaves in Windows, it is definitely not straightforward enough. So this is how you do this:

C#:

terminalControl.SendToServer(new ConsoleKeyInfo('\x3', ConsoleKey.C, false, false, true));

VB.NET:

terminalControl.SendToServer(New ConsoleKeyInfo(Convert.ToChar(3), ConsoleKey.C, False, False, True))

(where terminalControl is an instance of TerminalControl or VirtualTerminal class)

This code creates a ConsoleKeyInfo that simulates a key with ASCII code 3 (ETX special character), console key ā€˜C’ and a pressed Ctrl key. This simulated keystroke is then sent to the server using the SendToServer method.

UPDATE: Are your curious why using '\x3' equals to sending Ctrl+C? Do you want to know other common control codes? Check the table in following Wikipedia article: wikipedia.org/wiki/ASCII#ASCII_control_characters

Published Thursday, August 13, 2009 5:46 PM by Lukas Pokorny

Comments

 

John Vottero said:

But, Ssh.StartShell() returns a Shell which doesn't have a SendToServer method.  How can I send a Ctrl/C to a Shell?

October 12, 2009 11:06 PM
New Comments to this post are disabled
Powered by Community Server (Personal Edition), by Telligent Systems