Example #1
0
        public override void Execute(Server server, Client client, string args)
        {
            string[] parts = args.Split('/');

            if (2 != parts.Length) {
                client.Send("Error: invalid mouse position");
                return;
            }

            double xPercent, yPercent;

            try {
                xPercent = double.Parse(parts[0]);
                yPercent = double.Parse(parts[1]);

                if (!(0d <= xPercent && xPercent < 1d)) {
                    throw new ArgumentOutOfRangeException("xPercent");
                }

                if (!(0d <= yPercent && yPercent < 1d)) {
                    throw new ArgumentOutOfRangeException("yPercent");
                }
            } catch {
                client.Send("Error: invalid mouse position");
                return;
            }

            IntPtr hWnd = WindowHandle;

            if (IntPtr.Zero == hWnd) {
                client.Send("Error: couldn't get window handle");
                return;
            }

            RECT clientSize = new RECT();
            if (!Win32Window.GetClientRect(hWnd, out clientSize)) {
                client.Send("Error: GetClientRect failed");
                return;
            }

            Point clientPos = new Point();
            if (!Win32Window.ClientToScreen(hWnd, ref clientPos)) {
                client.Send("Error: ClientToScreen failed");
                return;
            }

            int x = clientPos.X + (int)(xPercent * clientSize.Width);
            int y = clientPos.Y + (int)(yPercent * clientSize.Height);

            if (!Win32Input.Move(x, y)) {
                client.Send("Error: Move() returned false");
                return;
            }

            client.Send("Set mouse position: {0},{1}", x, y);
        }
Example #2
0
 internal void RemoveClient(Client client)
 {
     clients.Remove(client);
 }
Example #3
0
 public abstract void Execute(Server server, Client client, string args);
 public ClientLogHandler(Client client)
 {
     this.client = client;
 }
Example #5
0
        public override void Execute(Server server, Client client, string args)
        {
            if (IntPtr.Zero == WindowHandle) {
                client.Send("Error: couldn't get window handle");
                return;
            }

            RECT size = new RECT();
            if (!Win32Window.GetWindowRect(new HandleRef(this, WindowHandle), out size)) {
                client.Send("Error: GetWindowRect failed");
                return;
            }

            if (null == bitmap || bitmap.Width != size.Width || bitmap.Height != size.Height) {
                if (null != bitmap) {
                    bitmap.Dispose();
                }

                bitmap = new Bitmap(size.Width, size.Height);
            }

            using (Graphics g = Graphics.FromImage(bitmap)) {
                Win32Window.PrintWindow(WindowHandle, g.GetHdc(), 0);
                g.ReleaseHdc();
            }

            // crop to just the client area
            RECT clientSize = new RECT();
            if (!Win32Window.GetClientRect(WindowHandle, out clientSize)) {
                client.Send("Error: GetClientRect failed");
                return;
            }

            Point clientPos = new Point();
            if (!Win32Window.ClientToScreen(WindowHandle, ref clientPos)) {
                client.Send("Error: ClientToScreen failed");
                return;
            }

            // ok for a one time thing but wasteful for continual use
            //Bitmap srcBitmap = bitmap.Clone(new Rectangle(
            //        clientPos.X - size._Left,
            //        clientPos.Y - size._Top,
            //        clientSize.Width,
            //        clientSize.Height),
            //    PixelFormat.Format32bppArgb);

            if (null == clientArea ||
                    clientArea.Width != clientSize.Width ||
                    clientArea.Height != clientArea.Height) {
                if (null != clientArea) {
                    clientArea.Dispose();
                }

                clientArea = new Bitmap(clientSize.Width, clientSize.Height);
                clientSrcRect = new Rectangle(
                    clientPos.X - size._Left,
                    clientPos.Y - size._Top,
                    clientSize.Width,
                    clientSize.Height);
                clientDestRect = new Rectangle(Point.Empty, clientArea.Size);
            }

            using (Graphics g = Graphics.FromImage(clientArea)) {
                g.DrawImage(bitmap, clientDestRect, clientSrcRect, GraphicsUnit.Pixel);
            }

            Bitmap srcBitmap = clientArea;

            if (client.settings.CaptureScale < 1f) {
                int nWidth  = (int)(srcBitmap.Width  * client.settings.CaptureScale);
                int nHeight = (int)(srcBitmap.Height * client.settings.CaptureScale);

                if (null == bitmapSmall ||
                        bitmapSmall.Width != nWidth ||
                        bitmapSmall.Height != nHeight) {
                    if (null != bitmapSmall) {
                        bitmapSmall.Dispose();
                    }

                    bitmapSmall = new Bitmap(nWidth, nHeight);
                }

                using (Graphics g = Graphics.FromImage(bitmapSmall)) {
                    g.DrawImage(srcBitmap, 0, 0, nWidth, nHeight);
                }

                srcBitmap = bitmapSmall;
            }

            using (MemoryStream s = new MemoryStream()) {
                if (null == encoderParams) {
                    encoderParams = new EncoderParameters(1);
                }

                if (null == qualityParam || lastQuality != client.settings.CaptureQuality) {
                    lastQuality = client.settings.CaptureQuality;
                    qualityParam = new EncoderParameter(
                        System.Drawing.Imaging.Encoder.Quality,
                        (long)Math.Round(lastQuality * 100)); // must be long
                    encoderParams.Param[0] = qualityParam;
                }

                srcBitmap.Save(s, JpegCodec, encoderParams);

                //using (FileStream f = new FileStream("test.jpg", FileMode.Create)) {
                //	s.WriteTo(f);
                //}

                //client.Send(string.Format("DBG: Length is {0} (0x{0:X})", s.Length));
                client.Send(false, "Success! 4-byte length and JPEG stream follow (length={0})", s.Length);
                client.Send(BitConverter.GetBytes((int)s.Length), false);
                s.WriteTo(client.Stream);
                client.Send();
            }
        }