No problem, here is the code for an interaction that allows you to connect to Screen Monkey using a TCP terminal and control the program.
I am a little unsure on exactly what you want to achieve, it might be helpful if you could explain in more detail so I can help you more.
/// <summary>
/// Allows control of Screen Monkey using a TCP terminal.
/// </summary>
public class TerminalInteraction:InteractionBase
{
IPanelInteraction _panelControl = null;
IScreenInteraction _screenControl = null;
IProfileInteraction _profileControl = null;
IClipLibraryInteraction _libraryControl = null;
private TcpTerminalServer server = new TcpTerminalServer();
/// <summary>
/// The name of this plugin.
/// </summary>
public override string Name
{
get { return "Terminal"; }
}
/// <summary>
/// A description about what this plugin does.
/// </summary>
public override string Description
{
get { return "Provides a TCP control terminal on port 3700"; }
}
/// <summary>
/// The name used when displaying to the user this plugin.
/// </summary>
public override string Caption
{
get { return "TCP Terminal"; }
}
/// <summary>
/// Who created the plugin.
/// </summary>
public override string Author
{
get { return "Oliver Waits"; }
}
/// <summary>
/// A string to represent the version of the plugin.
/// </summary>
public override string Version
{
get { return "1.0"; }
}
/// <summary>
/// Starts the interaction plugin and initialises the interactions.
/// This is called when Screen Monkey first starts and an interface provider
/// is passed in which you can use to query usful interfaces to perform functions
/// within Screen Monkey.
/// </summary>
/// <param name="interfaceProvider">The Screen Monkey interface provider. </param>
public override void Start(IInterfaceProvider interfaceProvider)
{
base.Start(interfaceProvider);
//Get the Panel interface to do things like change clip page.
_panelControl = (IPanelInteraction)_interfaceProvider.GetInterface(typeof(IPanelInteraction));
//Get the screen interface to play clips.
_screenControl = (IScreenInteraction)_interfaceProvider.GetInterface(typeof(IScreenInteraction));
//Get the profile interface to change the display profile.
_profileControl = (IProfileInteraction)_interfaceProvider.GetInterface(typeof(IProfileInteraction));
//Get the library interface to add and remove clips.
_libraryControl = (IClipLibraryInteraction)_interfaceProvider.GetInterface(typeof(IClipLibraryInteraction));
//Open a TCP terminal server that accepts text commands. Compatible with terminals such as PUTTY.
server.TerminalCommand += new EventHandler<TerminalCommandEventArgs>(server_TerminalCommand);
server.Port = 3700;
server.Start();
}
/// <summary>
/// Called when Screen Monkey is closing and should be used to perform any cleanup operations.
/// </summary>
public override void Stop()
{
base.Stop();
//Stops the terminal server and closes any ports.
server.Stop();
}
/// <summary>
/// Called when a new command is recieved over the TCP terminal.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void server_TerminalCommand(object sender, TerminalCommandEventArgs e)
{
TerminalRootOptions rootOptions = new TerminalRootOptions();
TerminalOptions subOption = null;
if (ProcessCommand(e.Client, rootOptions, e.Command, true))
{
if (rootOptions.Play) subOption = new PlayOptions();
else if(rootOptions.Clear) subOption = new ClearOptions();
else if (rootOptions.Layer>0) subOption = new LayerOptions();
else if (rootOptions.Clip) subOption = new ClipOptions();
else if (rootOptions.Pause) _screenControl.Pause();
else if (rootOptions.Go) _screenControl.Go();
if (subOption != null)
{
if (ProcessCommand(e.Client, subOption, e.Command, false))
{
if (subOption is PlayOptions) ProcessPlay((PlayOptions) subOption);
if (subOption is ClearOptions) ProcessClear((ClearOptions) subOption);
if (subOption is LayerOptions) ProcessLayer((LayerOptions)subOption);
if (subOption is ClipOptions) ProcessClip((ClipOptions)subOption);
}
}
}
}
/// <summary>
/// Plays a clip in Screen Monkey.
/// </summary>
/// <param name="options">Information about which clip to play.</param>
private void ProcessPlay(PlayOptions options)
{
//Does the command specify a clip id or handle index.
if(options.Id)
//Play the clip by clip id.
_screenControl.PlayClip(options.Clip);
else
//Play the clip by handle index. This is the index of the clip on a page.
_panelControl.PlayClip(options.Clip - 1);
}
/// <summary>
/// Clears the screen
/// </summary>
/// <param name="options">Not Used</param>
private void ProcessClear(ClearOptions options)
{
//Clears the screen and stops all clips.
_screenControl.ClearScreen();
}
/// <summary>
/// Adds or removes clips from the library.
/// </summary>
/// <param name="options"></param>
private void ProcessClip(ClipOptions options)
{
if (options.Add)
{
if (options.Filename != "")
{
_libraryControl.AddFile(options.Filename);
}
}
_screenControl.ClearScreen();
}
/// <summary>
/// Changes the opacity of a layer.
/// </summary>
/// <param name="options"></param>
private void ProcessLayer(LayerOptions options)
{
if (options.Layer>0 && options.Layer <= _profileControl.ActiveProfile.Layers.Count)
{
if(options.Transparency>=0) _profileControl.ActiveProfile.Layers[options.Layer-1].Opacity = (float)options.Transparency / 100;
}
}
/// <summary>
/// Called when a new command ocurrs.
/// </summary>
/// <param name="client"></param>
/// <param name="options"></param>
/// <param name="command"></param>
/// <param name="ignoreErrors"></param>
/// <returns></returns>
private bool ProcessCommand(TcpTerminalClient client, TerminalOptions options, string command, bool ignoreErrors)
{
CommandLineParser parser = new CommandLineParser(options);
parser.Parse(command, false);
if (options.ShowHelp())
{
client.Send(parser.UsageInfo.GetHeaderAsString(78));
client.Send(parser.UsageInfo.GetOptionsAsString(78));
return false;
}
else if (parser.HasErrors)
{
if (ignoreErrors) return true;
client.Send(parser.UsageInfo.GetErrorsAsString(78));
return true;
}
return true;
}
/// <summary>
/// Saves any settings for this plugin. The settings should be written to the Xml writer.
/// </summary>
/// <param name="writer"></param>
public override void SaveSettings(System.Xml.XmlWriter writer)
{
}
/// <summary>
/// Loads any setting which have been saved for this plugin.
/// </summary>
/// <param name="settings"></param>
public override void LoadSettings(System.Xml.XmlNode settings)
{
}
}