コード例 #1
0
        private static void ExecuteSelectedAutoType(EcasAction a, EcasContext ctx)
        {
            try
            {
                // Do not Spr-compile the sequence here; it'll be compiled by
                // the auto-type engine (and this expects an auto-type sequence
                // as input, not a data string; compiling it here would e.g.
                // result in broken '%' characters in passwords)
                string strSeq = EcasUtil.GetParamString(a.Parameters, 0, false);
                if (string.IsNullOrEmpty(strSeq))
                {
                    strSeq = null;
                }

                PwEntry pe = Program.MainForm.GetSelectedEntry(true);
                if (pe == null)
                {
                    return;
                }
                PwDatabase pd = Program.MainForm.DocumentManager.SafeFindContainerOf(pe);

                IntPtr hFg = NativeMethods.GetForegroundWindowHandle();
                if (GlobalWindowManager.HasWindowMW(hFg))
                {
                    AutoType.PerformIntoPreviousWindow(Program.MainForm, pe,
                                                       pd, strSeq);
                }
                else
                {
                    AutoType.PerformIntoCurrentWindow(pe, pd, strSeq);
                }
            }
            catch (Exception) { Debug.Assert(false); }
        }
コード例 #2
0
        internal static bool LoseFocus(Form fCurrent, bool bSkipOwnWindows)
        {
            if (NativeLib.IsUnix())
            {
                return(LoseFocusUnix(fCurrent));
            }

            try
            {
                IntPtr hWnd = ((fCurrent != null) ? fCurrent.Handle : IntPtr.Zero);

                while (true)
                {
                    IntPtr hWndPrev = hWnd;
                    hWnd = GetWindow(hWnd, GW_HWNDNEXT);

                    if (hWnd == IntPtr.Zero)
                    {
                        return(false);
                    }
                    if (hWnd == hWndPrev)
                    {
                        Debug.Assert(false); return(false);
                    }

                    int nStyle = GetWindowStyle(hWnd);
                    if ((nStyle & WS_VISIBLE) == 0)
                    {
                        continue;
                    }

                    if (GetWindowTextLength(hWnd) == 0)
                    {
                        continue;
                    }

                    if (bSkipOwnWindows && GlobalWindowManager.HasWindowMW(hWnd))
                    {
                        continue;
                    }

                    // Skip the taskbar window (required for Windows 7,
                    // when the target window is the only other window
                    // in the taskbar)
                    if (IsTaskBar(hWnd))
                    {
                        continue;
                    }

                    break;
                }

                Debug.Assert(GetWindowText(hWnd, true) != "Start");
                return(EnsureForegroundWindow(hWnd));
            }
            catch (Exception) { Debug.Assert(false); }

            return(false);
        }
コード例 #3
0
ファイル: AutoType.cs プロジェクト: kkato233/KeePass
        public static bool IsValidAutoTypeWindow(IntPtr hWnd, bool bBeepIfNot)
        {
            bool bValid = !GlobalWindowManager.HasWindowMW(hWnd);

            if (!bValid && bBeepIfNot)
            {
                SystemSounds.Beep.Play();
            }

            return(bValid);
        }