public MainForm() { InitializeComponent(); CurrentIdleState = IdleStates.Unset; Mousepad = new Mousepad(); Keyboard = new KeyboardEventRunner(); Broadcaster = new ClientBroadcastSignaler(37015); Receiver = new Receiver(37015); Receiver.Start(); Receiver.OnError += Receiver_OnError; Receiver.OnMouseMove += (o, e) => { Mousepad.MoveMouse(e.X, e.Y); }; Receiver.OnMouseLeftClick += (o, e) => { Mousepad.LeftClick(); }; Receiver.OnMouseRightClick += (o, e) => { Mousepad.RightClick(); }; Receiver.OnMouseDoubleLeftClick += (o, e) => { Mousepad.LeftDoubleClick(); }; Receiver.OnMouseLeftPress += (o, e) => { Mousepad.LeftDown(); }; Receiver.OnMouseLeftRelease += (o, e) => { Mousepad.LeftUp(); }; Receiver.OnScrollwheelMove += (o, e) => { if (e > 0) { Mousepad.ScrollDown(); } else { Mousepad.ScrollUp(); } }; Receiver.OnMouseSignalReceived += Receiver_OnMouseSignalReceived; LastMessage = DateTime.Now; IdleLoopThread = new Thread(new ThreadStart(IdleTimerLoop)); IdleLoopThread.IsBackground = true; IdleLoopThread.Start(); HandleIdleStateChange(); }
private static void RunProtoLoop() { //setup network var udp = new UdpNetworkConnection <string>(new AsciiSerializer()); udp.StartListening(37015); udp.Target(IPAddress.Broadcast.ToString(), 37015); //run broadcast var broadcastLoop = Fork(() => { var myHostname = Dns.GetHostAddresses(Dns.GetHostName()).First(host => host.AddressFamily == AddressFamily.InterNetwork).ToString(); while (true) { Thread.Sleep(1000); udp.Send(myHostname); } }); //var joystic = new MouseJoystic(); var joystic = new Mousepad(); joystic.SetMovementScale(1f); //andle messages udp.OnMessageReceived += (sender, args) => { //validate if (!args.StartsWith("[") || !args.EndsWith("]")) { return; } //parse var tokens = args.Trim('[', ']').Split(':'); switch (tokens[0]) { case "down": //set to 0 to prep { float x, y; var pieces = tokens[1].Split(','); if (float.TryParse(pieces[0], out x) && float.TryParse(pieces[1], out y)) { //joystic.Start(x, y); } break; } case "up": //set to 0 to make it stop { float x, y; var pieces = tokens[1].Split(','); if (float.TryParse(pieces[0], out x) && float.TryParse(pieces[1], out y)) { //joystic.Stop(x, y); } break; } case "move": //set to input { float x, y; var pieces = tokens[1].Split(','); if (float.TryParse(pieces[0], out x) && float.TryParse(pieces[1], out y)) { //joystic.Moved(x, y); } else { } break; } case "click_left": { joystic.LeftClick(); break; } case "click_right": { joystic.RightClick(); break; } default: { break; } } }; //hold UI while (true) { Console.ReadKey(); } }