the main goal is to control a few video programs such as vmc and power dvd from another computer.
there are a few commands that require the windows key such as to start vmc. I have searched to find a solution but can't find anything that explains how to accomplish this only pieces.
Here is the code so far.
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Diagnostics;
using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;
class MyTcpListener
{
public static void Main()
{
TcpListener server = null;
try
{
// Get host name
String strHostName = Dns.GetHostName();
Console.WriteLine("Host Name: " + strHostName);
// Find host by name
IPHostEntry iphostentry = Dns.GetHostByName(strHostName);
// Enumerate IP addresses
int nIP = 0;
// Set the TcpListener on port 50000.
Int32 port = 50000;
// TcpListener server = new TcpListener(port);
server = new TcpListener(iphostentry.AddressList[nIP], port);
// Start listening for client requests.
server.Start();
// Buffer for reading data
Byte[] bytes = new Byte[256];
String data = null;
// Enter the listening loop.
while (true)
{
Console.Write("Waiting for a connection... ");
// Perform a blocking call to accept requests.
// You could also user server.AcceptSocket() here.
TcpClient client = server.AcceptTcpClient();
Console.WriteLine("Connected!");
data = null;
NetworkStream stream = client.GetStream();
string sendmsg;
decide:
sendmsg = "Type \"continue\" to go on or \"quit\" to stop: \r\r";
byte[] msg = System.Text.Encoding.ASCII.GetBytes(sendmsg);
stream.Write(msg, 0, msg.Length);
string myInput;
StreamReader streamReader = new StreamReader(client.GetStream());
string line = streamReader.ReadLine();
Console.WriteLine(line);
switch (line)
{
case "continue":
System.Windows.Forms.SendKeys.SendWait("A");
System.Windows.Forms.SendKey(70, 18, 1);
goto decide;
case "string":
Console.WriteLine("auto input detected\r");
goto decide;
case "quit":
Console.WriteLine("Bye.");
break;
default:
Console.WriteLine("Your input {0} is incorrect.", data);
goto decide;
}
// Shutdown and end connection
break;
}
}
catch (SocketException e)
{
Console.WriteLine("SocketException: {0}", e);
}
finally
{
// Stop listening for new clients.
server.Stop();
}
}
}


Sign In
Create Account


Back to top









