愚かなことに私はあなたの質問を完全に読まなかったので、私は私の答えを編集しなければならなかった。
シンプルな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);
だから、第二の溶液での問題は、あなたが管理者権限でそれを実行することができなかったことでしたか? –
いいえ、管理者権限で実行したときに入力がブロックされました。しかし、入力がブロックされていても、_pointer_が動かずにキーボード入力が無視されても(キーは押されていてもテキストはありませんでしたが)、マウスを動かすかキーボード上のキーを押して(物理的に)メモ帳に入力します)。 –
sleepコマンドを送信する前に入力をブロックする方法 – RomCoo