private delegate void DelegatePrintf(String str);//委托 String Control(String strJson, String addr) { DelegatePrintf print = new DelegatePrintf(printf); try { JObject jsonObj = JObject.Parse(strJson); //获取版本号 if (jsonObj["version"] != null) { return(new JObject(new JProperty("version", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString())).ToString()); } //配对 if (jsonObj["auth"] != null) { String auth = Encoding.UTF8.GetString(Convert.FromBase64String(jsonObj["auth"].ToString())); if (auth.Equals(key)) { client = addr; Invoke(print, "连接成功 " + addr); return(new JObject(new JProperty("state", "correct")).ToString()); } else { Thread.Sleep(500); Invoke(print, "连接失败 " + addr + " " + auth); return(new JObject(new JProperty("state", "wrong")).ToString()); } } if (client.Equals(addr)) { if (jsonObj["mouse"] != null) { //mouse_event(Convert.ToInt32(jsonObj["dwFlags"].ToString()), Convert.ToInt32(jsonObj["dx"].ToString()), Convert.ToInt32(jsonObj["dy"].ToString()), Convert.ToInt32(jsonObj["cButtons"].ToString()), Convert.ToInt32(jsonObj["dwExtraInfo"].ToString())); JObject jsonMouse = JObject.Parse(jsonObj["mouse"].ToString()); INPUT input = new INPUT(); input.type = (int)InputType.INPUT_MOUSE; input.mi.dx = (int)jsonMouse["dx"]; input.mi.dy = (int)jsonMouse["dy"]; input.mi.dwData = (int)jsonMouse["dwData"]; input.mi.dwFlags = (int)jsonMouse["dwFlags"]; SendInput(1, ref input, Marshal.SizeOf(input)); } if (jsonObj["keybd"] != null) { //keybd_event(Convert.ToByte(jsonObj["bVk"].ToString()), Convert.ToByte(jsonObj["bScan"].ToString()), Convert.ToUInt32(jsonObj["dwFlags"].ToString()), Convert.ToUInt32(jsonObj["dwExtraInfo"].ToString())); JObject jsonKeybd = JObject.Parse(jsonObj["keybd"].ToString()); INPUT input = new INPUT(); input.type = (int)InputType.INPUT_KEYBOARD; input.ki.wVk = (short)jsonKeybd["wVk"]; //input.ki.wScan = Convert.ToInt16(jsonKeybd["wScan"].ToString()); input.ki.dwFlags = (int)jsonKeybd["dwFlags"]; SendInput(1, ref input, Marshal.SizeOf(input)); } if (jsonObj["text"] != null) { SendText(jsonObj["text"].ToString()); } if (jsonObj["exit"] != null) { client = ""; Invoke(print, "断开连接"); } } return(""); } catch (Exception) { Invoke(print, "参数有误!"); return(""); } }
private delegate void DelegatePrintf(String str);//委托 String Control(String strJson, String addr) { DelegatePrintf print = new DelegatePrintf(printf); try { JObject jsonObj = JObject.Parse(strJson); //获取版本号 if (jsonObj["version"] != null) { return new JObject(new JProperty("version", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString())).ToString(); } //配对 if (jsonObj["auth"] != null) { String auth = Encoding.UTF8.GetString(Convert.FromBase64String(jsonObj["auth"].ToString())); if (auth.Equals(key)) { client = addr; Invoke(print, "连接成功 " + addr); return new JObject(new JProperty("state", "correct")).ToString(); } else { Thread.Sleep(500); Invoke(print, "连接失败 " + addr + " " + auth); return new JObject(new JProperty("state", "wrong")).ToString(); } } if (client.Equals(addr)) { if (jsonObj["mouse"] != null) { //mouse_event(Convert.ToInt32(jsonObj["dwFlags"].ToString()), Convert.ToInt32(jsonObj["dx"].ToString()), Convert.ToInt32(jsonObj["dy"].ToString()), Convert.ToInt32(jsonObj["cButtons"].ToString()), Convert.ToInt32(jsonObj["dwExtraInfo"].ToString())); JObject jsonMouse = JObject.Parse(jsonObj["mouse"].ToString()); INPUT input = new INPUT(); input.type = (int)InputType.INPUT_MOUSE; input.mi.dx = (int)jsonMouse["dx"]; input.mi.dy = (int)jsonMouse["dy"]; input.mi.dwData = (int)jsonMouse["dwData"]; input.mi.dwFlags = (int)jsonMouse["dwFlags"]; SendInput(1, ref input, Marshal.SizeOf(input)); } if (jsonObj["keybd"] != null) { //keybd_event(Convert.ToByte(jsonObj["bVk"].ToString()), Convert.ToByte(jsonObj["bScan"].ToString()), Convert.ToUInt32(jsonObj["dwFlags"].ToString()), Convert.ToUInt32(jsonObj["dwExtraInfo"].ToString())); JObject jsonKeybd = JObject.Parse(jsonObj["keybd"].ToString()); INPUT input = new INPUT(); input.type = (int)InputType.INPUT_KEYBOARD; input.ki.wVk = (short)jsonKeybd["wVk"]; //input.ki.wScan = Convert.ToInt16(jsonKeybd["wScan"].ToString()); input.ki.dwFlags = (int)jsonKeybd["dwFlags"]; SendInput(1, ref input, Marshal.SizeOf(input)); } if (jsonObj["text"] != null) { SendText(jsonObj["text"].ToString()); } if (jsonObj["exit"] != null) { client = ""; Invoke(print, "断开连接"); } } return ""; } catch (Exception) { Invoke(print, "参数有误!"); return ""; } }