Esempio n. 1
0
        static void perform(int action, Keys key)
        {
            if (!Working)
            {
                return;
            }
            if (ExcludedKeys.Contains(key))
            {
                return;
            }
            var fore = Win32ApiWrapper.GetForegroundWindow();

            if (!MainWindows.Any(w => w.SameOrBelongTo(fore)))
            {
                return;
            }
            WorkingNotice?.BeginInvoke(fore, null, null);
            for (var i = AllWindows.Count - 1; i >= 0; i--)
            {
                var item = AllWindows[i];
                var w    = item.Key;
                if (w.SameOrBelongTo(fore))
                {
                    continue;
                }
                var r = Win32ApiWrapper.PostMessage(w, action, (int)key, 0);
                if (r == 0)
                {
                    AllWindows.Remove(item);
                    WindowLost?.BeginInvoke(w, null, null);
                }
            }
        }
Esempio n. 2
0
        static void executeKeysQueue(KeysQueue queue)
        {
            Collect();
            switch (queue.Id)
            {
            case -1:
                if (queue.Index > -1)
                {
                    if (AllWindows.Count > queue.Index)
                    {
                        var w = AllWindows[queue.Index].Key;
                        if (!w.SameOrBelongTo(Win32ApiWrapper.GetForegroundWindow()))
                        {
                            w.SwitchToThisWindow();
                            WorkingNotice?.BeginInvoke(w, null, null);
                        }
                    }
                }
                break;

            case 0:
                if (queue.Index == -1)      //Toggle: NaN key
                {
                    if (Working)
                    {
                        Stop();
                    }
                    else
                    {
                        Start();
                    }
                }
                else        //PostMessage: NaN key + N keys
                {
                    if (AllWindows.Count > queue.Index)
                    {
                        var w = AllWindows[queue.Index].Key;
                        if (queue.Starter == queue.Empty)      //for accuration.
                        {
                            var k = (int)queue.IdToggler;
                            Win32ApiWrapper.PostMessage(w, WinApiConsts.Msg.WM_KEYDOWN, k, 0);
                            if (SendKeyUp)
                            {
                                Win32ApiWrapper.PostMessage(w, WinApiConsts.Msg.WM_KEYUP, k, 0);
                            }
                        }
                    }
                }
                break;

            case 1:
                SendKeyUp = !SendKeyUp;
                try {
                    SendKeyUpChanged?.BeginInvoke(null, null);
                } catch {
                }
                break;

            default:                              //ShowWindow: SW_MINIMIZE/SW_NORMAL
                if (queue.Starter == queue.Empty) //for accuration
                {
                    if (queue.Index == -1)        //for accuration
                    {
                        var c = Win32ApiWrapper.GetForegroundWindow();
                        if (AllWindows.Any(w => w.Key.SameOrBelongTo(c)))      //find current
                        {
                            var iconic   = AllWindows.Any(w => Win32ApiWrapper.IsIconic(w.Key.TillDesktop()));
                            var nCmdShow = iconic ? WinApiConsts.nCmdShow.SW_NORMAL : WinApiConsts.nCmdShow.SW_MINIMIZE;
                            foreach (var item in AllWindows.Select(w => w.Key))
                            {
                                if (item.SameOrBelongTo(c))      //keep current
                                {
                                    continue;
                                }
                                Win32ApiWrapper.ShowWindow(item.TillDesktop(), nCmdShow);
                            }
                            c.SwitchToThisWindow();
                        }
                    }
                }
                break;
            }
        }