public static void restrictArea(IntPtr hwnd, bool center, bool restrict)
 {
     if (center || restrict)
     {
         ContentCapture.User32.RECT r = new ContentCapture.User32.RECT();
         ContentCapture.User32.GetWindowRect(hwnd, ref r);
         if (center)
         {
             setMousePos(r.left + ((r.right - r.left) / 2), r.top + ((r.bottom - r.top) / 2));
         }
         if (restrict)
         {
             setMouseArea(r.left, r.top, (r.right - r.left), (r.bottom - r.top));
         }
     }
 }
        static void Main(string[] args)
        {
            hwnd               = IntPtr.Zero;
            datavalid          = false;
            bms                = BabylonMS.BabylonMS.ShipDocking(shipUUID, args);
            bms.Connected     += ClientConnected;
            bms.Disconnected  += Disconnected;
            bms.NewInputFrame += NewInputFrame;
            bms.OpenGate(false);//client


            stopWatch = Stopwatch.StartNew();
            while (true)
            {
                if (datavalid)
                {
                    if (stopWatch.ElapsedMilliseconds > mintime)
                    {
                        stopWatch.Restart();
                        try
                        {
                            ContentCapture.User32.RECT r = new ContentCapture.User32.RECT();
                            ContentCapture.User32.GetWindowRect(hwnd, ref r);
                            MemoryStream zmem = new BabylonMS.zipper(ContentCapture.CaptureWindowToStream(hwnd, JPEGQuality)).GetZip(false);

                            BabylonMS.BMSField data  = screensession.outputPack.GetFieldByName("DATA");
                            BabylonMS.BMSField recta = screensession.outputPack.GetFieldByName("RECT");
                            if (data != null)
                            {
                                data.Value(zmem.ToArray());
                            }
                            if (recta != null)
                            {
                                recta.Value((Int16)r.left);
                                recta.Value((Int16)r.top);
                                recta.Value((Int16)r.right);
                                recta.Value((Int16)r.bottom);
                            }
                            if (!screensession.TransferPacket(true))
                            {
                                Disconnected(null);
                            }
                            if (data != null)
                            {
                                data.clearValue();
                            }
                            if (recta != null)
                            {
                                recta.clearValue();
                            }
                        }
                        catch (Exception) {
                            Disconnected(null);
                        };
                    }
                    else
                    {
                        Thread.Sleep(10);
                    }
                }
                else
                {
                    Thread.Sleep(300);
                    live--;
                    if (live < 0)
                    {
                        Disconnected(null); //exit
                    }
                }
            }
        }