ばかげてあなたの質問を完全に読んでいなかったので、回答を編集する必要がありました。
単純な TCP サーバー/クライアント ソケットを介して相互に要求を送信する両方のコンピューターに常駐するアプリケーションを作成することをお勧めします。
これにより、たとえば、PC 1 のボタンを押してスリープ状態にし、モニターに対して同じことを行い、PC 2 にメッセージを送信してウェイクアップし、モニター入力を盗むことができます。この速度に関しては、いくつかの変数に依存すると思いますが、後で作業することができます。
TCP クライアント/サーバー:
using System;
using System.Net;
using System.Net.Sockets;
using System.Diagnostics;
using System.IO;
namespace ClientSocket_System
{
class tcpClientSocket
{
#region Global Variables
TcpClient tcpService;
IPEndPoint serverEndPoint;
NetworkStream netStream;
#endregion
public void commToServer()
{
tcpService = new TcpClient();
serverEndPoint = new IPEndPoint(IPAddress.Parse("xxx.xxx.xxx.xx"), xxxx); //Enter IP address of computer here along with a port number if needed
try
{
tcpService.Connect(serverEndPoint);
netStream = tcpService.GetStream();
ASCIIEncoding encoder = new ASCIIEncoding();
byte[] buffer = encoder.GetBytes("SwitchComputers");
netStream.Write(buffer, 0, buffer.Length);
netStream.Flush();
tcpService.Close();
}
catch(Exception ex)
{
}
}
}
}
そしてサーバー:
using System.Net;
using System.Net.Sockets;
using System.Diagnostics;
using System.IO;
namespace ClientSocket_System
{
class tcpServerTerminal
{
private TcpListener tcpListener;
private Thread listenThread;
private TcpClient tcpService;
string msgFromClient;
public void ServerStart()
{
tcpListener = new TcpListener(IPAddress.Any, 5565);
listenThread = new Thread(new ThreadStart(ListenForClients));
listenThread.Start();
}
public void ListenForClients()
{
tcpListener.Start();
while (true)
{
//blocks until a client has connected to the server
TcpClient client = this.tcpListener.AcceptTcpClient();
//create a thread to handle communication
//with connected client
Thread clientThread = new Thread(new ParameterizedThreadStart(HandleClientComm));
clientThread.Start(client);
}
}
public void HandleClientComm(object client)
{
tcpService = (TcpClient)client;
NetworkStream netStream = tcpService.GetStream();
byte[] message = new byte[4096];
int bytesRead;
while (true)
{
bytesRead = 0;
try
{
//blocks until a client sends a message
bytesRead = netStream.Read(message, 0, 4096);
}
catch
{
//a socket error has occured
break;
}
if (bytesRead == 0)
{
//the client has disconnected from the server
break;
}
//message has successfully been received
ASCIIEncoding encoder = new ASCIIEncoding();
msgFromClient = encoder.GetString(message, 0, bytesRead);
if (msgFromClient == "SwitchComputers")
{
//RUN CODE HERE TO ACTION PC SLEEP AND MONITOR SLEEP
msgFromClient = null;
}
}
}
public void SocketSend()
{
NetworkStream streamToClient = tcpService.GetStream();
ASCIIEncoding encoder = new ASCIIEncoding();
byte[] buffer = encoder.GetBytes("SwitchComputers");
streamToClient.Write(buffer, 0, buffer.Length);
streamToClient.Flush();
}
}
}
少なくとも検討する価値があるかもしれませんが、上記のコードは正確には洗練されていませんが、ホームネットワークを介して両方のコンピューターのアクションを制御し、特定のコマンドを同時に実行できるようにすることができます:スリープ/ウェイクなど.
これにより、調査の新しい方向性が得られることを願っています。
また、入力をブロックするためのコードを次のようにフォーマットするのがベストプラクティスだと思います。
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern bool BlockInput([In, MarshalAs(UnmanagedType.Bool)] bool fBlockIt);