From 7f1ea535ed007e1498e3aa7bd12bded7df5ba9f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Thu, 3 Nov 2022 15:40:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=99=A8=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HKHelper/TelevisionStart.cs | 251 +----------------------------------- 1 file changed, 2 insertions(+), 249 deletions(-) diff --git a/HKHelper/TelevisionStart.cs b/HKHelper/TelevisionStart.cs index 062fc69..6ed0da2 100644 --- a/HKHelper/TelevisionStart.cs +++ b/HKHelper/TelevisionStart.cs @@ -13,194 +13,17 @@ using System.Threading; namespace HKHelper { - - // 用于从远程设备接收数据的状态对象。 - //public class StateObject - //{ - // public Socket workSocket = null; - // public const int BufferSize = 16384; - // public byte[] buffer = new byte[BufferSize]; - // public StringBuilder sb = new StringBuilder(); - //} - - //public class AsynchronousClient - //{ - // private const int port = 9090; - // private static ManualResetEvent connectDone = new ManualResetEvent(false); - // private static ManualResetEvent sendDone = new ManualResetEvent(false); - // private static ManualResetEvent receiveDone = new ManualResetEvent(false); - // private static String response = String.Empty; - - // private static void StartClient() - // { - // try - // { - // IPHostEntry ipHostInfo = Dns.GetHostEntry("kwikwai.local"); - // IPAddress ipAddress = ipHostInfo.AddressList[0]; - // IPEndPoint remoteEP = new IPEndPoint(ipAddress, port); - - // Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - - // client.BeginConnect(remoteEP, new AsyncCallback(ConnectCallback), client); - // connectDone.WaitOne(5000); - - // Send(client, "cec:listen:set 1\r\n"); - // sendDone.WaitOne(5000); - - // Receive(client); - // receiveDone.WaitOne(10000); - - // client.Shutdown(SocketShutdown.Both); - // client.Close(); - - // } - // catch (Exception e) - // { - // Console.WriteLine(e.ToString()); - // } - // } - - // private static void ConnectCallback(IAsyncResult ar) - // { - // try - // { - // Socket client = (Socket)ar.AsyncState; - - // client.EndConnect(ar); - - // Console.WriteLine("Socket connected to {0}", client.RemoteEndPoint.ToString()); - - // connectDone.Set(); - // } - // catch (Exception e) - // { - // Console.WriteLine(e.ToString()); - // } - // } - - // private static void Receive(Socket client) - // { - // try - // { - // StateObject state = new StateObject(); - // state.workSocket = client; - // client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), state); - // } - // catch (Exception e) - // { - // Console.WriteLine(e.ToString()); - // } - // } - - // private static void ReceiveCallback(IAsyncResult ar) - // { - // try - // { - // StateObject state = (StateObject)ar.AsyncState; - // Socket client = state.workSocket; - - // int bytesRead = client.EndReceive(ar); - - // if (bytesRead > 0) - // { - // state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead)); - // Console.WriteLine(Encoding.ASCII.GetString(state.buffer, 0, bytesRead)); - - // client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), state); - // } - // else - // { - // if (state.sb.Length > 1) - // { - // response = state.sb.ToString(); - // } - // receiveDone.Set(); - // } - // } - // catch (Exception e) - // { - // Console.WriteLine(e.ToString()); - // } - // } - - // private static void Send(Socket client, String data) - // { - // byte[] byteData = Encoding.ASCII.GetBytes(data); - - // client.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), client); - // } - - // private static void SendCallback(IAsyncResult ar) - // { - // try - // { - // Socket client = (Socket)ar.AsyncState; - - // int bytesSent = client.EndSend(ar); - // sendDone.Set(); - // } - // catch (Exception e) - // { - // Console.WriteLine(e.ToString()); - // } - // } - - // public static int Main(String[] args) - // { - // StartClient(); - // return 0; - // } - //} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public class TelevisionStart { public static bool TurnOn() { - return SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1)!=0; + return SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1) != 0; } public static bool TurnOff() { - return SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2)!=0; + return SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2) != 0; } [DllImport("user32.dll")] @@ -209,77 +32,7 @@ namespace HKHelper private static readonly IntPtr HWND_BROADCAST = new IntPtr(0xffff); private const uint WM_SYSCOMMAND = 0x0112; private const int SC_MONITORPOWER = 0xf170; - - //public void TurnOn() - //{ - // SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1); - //} - - //public void TurnOff() - //{ - // SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2); - //} - - // 如果函数执行成功,返回值不为0。 - // 如果函数执行失败,返回值为0。要得到扩展错误信息,调用GetLastError。 - //[DllImport("user32.dll ", SetLastError = true)] - //public static extern bool RegisterHotKey(IntPtr hWnd, int id, KeyModifiers fsModifiers, Keys vk); - - //public static extern bool RegisterHotKey(IntPtr hWnd, // 要定义热键的窗口的句柄 - // int id, // 定义热键ID(不能与其它ID重复) - // KeyModifiers fsModifiers, // 标识热键是否在按Alt、Ctrl、Shift、Windows等键时才会生效 - // Keys vk // 定义热键的内容 - // ); - - //[DllImport("user32.dll ", SetLastError = true)] - //public static extern bool UnregisterHotKey(IntPtr hWnd, int id); - - //[DllImport("user32.dll ", SetLastError = true)] - //public static extern bool UnregisterHotKey( - // IntPtr hWnd, // 要取消热键的窗口的句柄 - // int id // 要取消热键的ID - // ); - - //[DllImport("user32.dll")] - //public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam); - - //private static readonly IntPtr HWND_BROADCAST = new IntPtr(0xffff); - //private const uint WM_SYSCOMMAND = 0x0112; - //private const int SC_MONITORPOWER = 0xf170; - - //protected override void WndProc(ref Message m) - //{ - // const int WM_HOTKEY = 0x0312; - // // 按快捷键 - // switch (m.Msg) - // { - // case WM_HOTKEY: - // switch (m.WParam.ToInt32()) - // { - // case 100: - // TurnOn(); - // break; - // case 101: - // TurnOff(); - // break; - // } - // break; - // } - // base.WndProc(ref m); - //} } - // 定义了辅助键的名称(将数字转变为字符以便于记忆,也可去除此枚举而直接使用数值) - [Flags()] - public enum KeyModifiers - { - None = 0, - Alt = 1, - Ctrl = 2, - Shift = 4, - WindowsKey = 8 - } - - }