Beispiel #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);
                }
            }
        }
Beispiel #2
0
 public static void Terminal()
 {
     if (kbhHook != 0)
     {
         Win32ApiWrapper.UnhookWindowsHookEx(kbhHook);
         kbhHook = 0;
     }
     Terminaled?.BeginInvoke(null, null);
 }
Beispiel #3
0
        public static IntPtr TillDesktop(this IntPtr self)
        {
            var p = Win32ApiWrapper.GetParent(self);

            if (p == IntPtr.Zero || p == desktop)
            {
                return(self);
            }
            return(TillDesktop(p));
        }
Beispiel #4
0
        public static void Prepare()
        {
            if (Preparing?.Invoke() == false)
            {
                return;
            }
            moduleName = moduleName ?? Process.GetCurrentProcess().MainModule.ModuleName;
            var intPtr = Win32ApiWrapper.GetModuleHandle(moduleName);

            kbhHook = Win32ApiWrapper.SetWindowsHookEx(WinApiConsts.HookType.WH_KEYBOARD_LL, hook, intPtr, 0);
            Prepared?.BeginInvoke(kbhHook != 0, null, null);
        }
Beispiel #5
0
        void Worker_Stopped()
        {
            var current = Win32ApiWrapper.GetForegroundWindow();

            if (Worker.MainWindows.Any(w => w.SameOrBelongTo(current)))
            {
                last = current;
            }
            Invoke(new Action(() => {
                run.Text           = "run";
                main.ReadOnly      = false;
                remove.ReadOnly    = false;
                pick.Enabled       = true;
                allWindows.Enabled = true;
                run.Focus();
            }));
        }
Beispiel #6
0
        public static bool SameOrBelongTo(this IntPtr self, IntPtr target)
        {
            if (self == target)
            {
                return(true);
            }
            var p = Win32ApiWrapper.GetParent(self);

            if (p.ToInt32() == 0)
            {
                return(false);
            }
            if (p == target)
            {
                return(true);
            }
            return(SameOrBelongTo(p, target));
        }
Beispiel #7
0
        void pick_Click(object sender, EventArgs e)
        {
            if (pick.Tag == null)
            {
                pick.Tag = new object();
                setTips("pick");
                return;
            }
            var i = Win32ApiWrapper.WindowFromPoint(Cursor.Position);

            if (i == Handle || Win32.SameOrBelongTo(i, Handle))
            {
                setTips("retry");
                return;
            }
            if (getAllWindows().ContainsKey(i))
            {
                setTips("already");
                shilver(getAllRows().First(r => (IntPtr)r.Tag == i));
                return;
            }
            var row = allWindows.Rows[allWindows.Rows.Add()];

            row.Tag = i;
            var cells = row.Cells;

            cells[0].Value = true;
            var sb = new StringBuilder(256);

            Win32ApiWrapper.GetWindowText(i, sb, sb.Capacity);
            if (sb.ToString().Length == 0)
            {
                Win32ApiWrapper.GetClassName(i, sb, sb.Capacity);
            }
            cells[1].Value = sb.ToString();
            cells[2].Value = '↑';
            cells[3].Value = 'X';
            Worker.Collect();
            shilver(row);
        }
Beispiel #8
0
 public static void SwitchToThisWindow(this IntPtr self)
 {
     Win32ApiWrapper.SwitchToThisWindow(self.TillDesktop(), true);
 }
Beispiel #9
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;
            }
        }
Beispiel #10
0
 void moveWindow(object sender, MouseEventArgs e)
 {
     Win32ApiWrapper.ReleaseCapture();
     Win32ApiWrapper.SendMessage(Handle, WinApiConsts.Msg.WM_SYSCOMMAND, WinApiConsts.SystemCommands.SC_DRAGMOVE, 0);
 }