Esempio n. 1
0
        bool _DontBlock(bool isInjected, LPARAM extraInfo, KKey vk = 0, bool isMMove = false)
        {
            if (_pause)
            {
                return(true);
            }
            if (isInjected)
            {
                //if(DontBlockInjected || (extraInfo != default && extraInfo == DontBlockInjectedExtraInfo)) return true;
                if (DontBlockInjected)
                {
                    return(true);
                }
            }
            AWnd w;

            if (vk != 0)
            {
                //var a = DontBlockKeys;
                //if(a != null) foreach(var k in a) if(vk == k) return true;
                w = AWnd.Active;
            }
            else
            {
                w = isMMove ? AWnd.Active : AWnd.FromMouse();
                //note: don't use hook's pt, because of a bug in some OS versions.
                //note: for wheel it's better to use FromMouse.
            }
            if (w.ThreadId == _threadId)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates image from a user-selected area of screen pixels. Or gets single pixel color, or just rectangle.
        /// Returns false if cancelled.
        /// </summary>
        /// <param name="result">Receives results.</param>
        /// <param name="flags"></param>
        /// <param name="toolWindow">Owner window. Temporarily hides it and its owner windows.</param>
        /// <remarks>
        /// Gets all screen pixels and shows in a full-screen topmost window, where the user can select an area.
        /// </remarks>
        public static bool CaptureUI(out WICResult result, WICFlags flags = 0, AnyWnd toolWindow = default)
        {
            result = default;

            switch (flags & (WICFlags.Image | WICFlags.Color | WICFlags.Rectangle))
            {
            case 0:
            case WICFlags.Image:
            case WICFlags.Color:
            case WICFlags.Rectangle: break;

            default: throw new ArgumentException();
            }

            AWnd[] aw = null; AWnd wTool = default;
            try {
                if (!toolWindow.IsEmpty)
                {
                    wTool = toolWindow.Wnd;
                    aw    = wTool.Get.OwnersAndThis(true);
                    foreach (var w in aw)
                    {
                        w.ShowLL(false);
                    }
                    using (new AInputBlocker(BIEvents.MouseClicks)) ATime.SleepDoEvents(300);                    //time for animations
                }

g1:
                RECT rs = SystemInformation.VirtualScreen;
                //RECT rs = AScreen.Primary.Bounds; //for testing, to see Write output in other screen
                Bitmap bs;
                bool   windowPixels = flags.HasAny(WICFlags.WindowDC | WICFlags.PrintWindow);
                if (windowPixels)
                {
                    if (!_WaitForHotkey("Press F3 to select window from mouse pointer."))
                    {
                        return(false);
                    }
                    var w = AWnd.FromMouse(WXYFlags.NeedWindow);
                    w.GetClientRect(out var rc, inScreen: true);
                    using var bw = Capture(w, w.ClientRect, flags.Has(WICFlags.PrintWindow));
                    bs           = new Bitmap(rs.Width, rs.Height);
                    using var g  = Graphics.FromImage(bs);
                    g.Clear(Color.Black);
                    g.DrawImage(bw, rc.left, rc.top);
                }
                else
                {
                    bs = Capture(rs);
                }

                var f = new _Form(bs, flags);
                f.Bounds = rs;
                switch (f.ShowDialog())
                {
                case DialogResult.OK: break;

                case DialogResult.Retry:
                    if (!windowPixels && !_WaitForHotkey("Press F3 when ready for new screenshot."))
                    {
                        return(false);
                    }
                    goto g1;

                default: return(false);
                }

                var r = f.Result;
                r.wnd  = _WindowFromRect(r);
                result = r;
            }
            finally {
                if (aw != null)
                {
                    foreach (var w in aw)
                    {
                        w.ShowLL(true);
                    }
                    if (wTool.IsAlive)
                    {
                        wTool.ShowNotMinimized();
                        wTool.ActivateLL();
                    }
                }
            }
            return(true);
        }