Ejemplo n.º 1
0
        /// <summary>
        /// 模擬觸控移動
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public PointerTouchInfo MakePointerTouchInfo(int x, int y)
        {
            uint orientation = 87;  //角度
            uint pressure    = 256; //壓力
            int  radius      = 1;   //觸控半徑

            PointerTouchInfo contact = new PointerTouchInfo();

            contact.PointerInfo.pointerType = PointerInputType.TOUCH;
            contact.TouchFlags  = TouchFlags.NONE;
            contact.Orientation = orientation;
            contact.Pressure    = pressure;
            contact.TouchMasks  = TouchMask.CONTACTAREA | TouchMask.ORIENTATION | TouchMask.PRESSURE;
            contact.PointerInfo.PtPixelLocation.X = x;
            contact.PointerInfo.PtPixelLocation.Y = y;
            uint unPointerId = IdGenerator.GetUinqueUInt();

            //Console.WriteLine("PointerId    " + unPointerId);
            contact.PointerInfo.PointerId = unPointerId;
            contact.ContactArea.left      = x - radius;
            contact.ContactArea.right     = x + radius;
            contact.ContactArea.top       = y - radius;
            contact.ContactArea.bottom    = y + radius;
            return(contact);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender2, EventArgs e2)
        {
            String html_path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "main_ui.html");

            if (File.Exists(html_path))
            {
                webBrowser1.Navigate(html_path);
                webBrowser1.ObjectForScripting = new C_js_to_net(this); //讓網頁允許存取C#
                webBrowser1.AllowNavigation    = false;                 //禁止載入其他網頁
                //webBrowser1.IsWebBrowserContextMenuEnabled = false;//禁止右鍵
            }
            else
            {
                webBrowser1.DocumentText = $"Can't find 「{html_path}」";
            }

            TouchInjector.InitializeTouchInjection();//初始化觸控API


            //
            var tim = new System.Windows.Forms.Timer();

            tim.Interval = 200;
            tim.Tick    += (sender, e) => {
                String gn = GetWindowsName.GetName();//取得目前焦點視窗的名稱

                //與「排除名單」進行比對
                foreach (var item in ar_ad)
                {
                    if (gn.IndexOf(item, StringComparison.CurrentCultureIgnoreCase) > -1)
                    {
                        bool_stop = true;
                        return;
                    }
                }
                bool_stop = false;
            };
            tim.Start();



            new Thread(() => {
                while (bool_exe_run)
                {
                    if (mtype == Mtype.滑鼠右鍵_2)
                    {
                        bool bool_d = bool_down_mr;

                        // Touch Down Simulate
                        if ((bool_down == false) && bool_d)
                        {
                            bool_down          = true;
                            pp                 = getPos();
                            pp_start           = pp;
                            bool_down_mr_moved = false;
                        }

                        // Touch Up Simulate
                        if (bool_down && (bool_d == false))
                        {
                            bool_down = false;

                            if (bool_down_mr_moved)
                            {
                                //模擬觸控-結束
                                contact.PointerInfo.PointerFlags = PointerFlags.UP;
                                TouchInjector.InjectTouchInput(1, new[] { contact });
                            }
                            else
                            {
                                RightClick();
                            }
                            bool_down_mr_moved = false;
                            //upFull();
                        }
                        else

                        // Touch Move Simulate
                        if (bool_down)
                        {
                            var p2 = getPos();

                            if (bool_down_mr_moved)
                            {
                                //模擬觸控-移動
                                int nMoveIntervalX = (int)((p2.X - pp.X) * f_touch_speed);
                                int nMoveIntervalY = (int)((p2.Y - pp.Y) * f_touch_speed);
                                contact.Move(nMoveIntervalX, nMoveIntervalY);
                                oFlags = PointerFlags.INRANGE | PointerFlags.INCONTACT | PointerFlags.UPDATE;
                                contact.PointerInfo.PointerFlags = oFlags;
                                TouchInjector.InjectTouchInput(1, new[] { contact });

                                //讓滑鼠跟隨觸控的位置
                                if (f_touch_speed != 1)
                                {
                                    NativeMethods.SetCursorPos(pp.X + nMoveIntervalX, pp.Y + nMoveIntervalY);
                                    p2 = getPos();
                                }

                                pp = p2;

                                if (overd_sc(pp))  //超出螢幕時自動停止觸控
                                {
                                    upFull();
                                }
                            }
                            else
                            {
                                if (func_位移(pp_start, p2))
                                {
                                    bool_down_mr_moved = true;

                                    //模擬觸控-開始
                                    contact = MakePointerTouchInfo(pp_start.X, pp_start.Y);
                                    oFlags  = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                                    contact.PointerInfo.PointerFlags = oFlags;
                                    bool bIsSuccess = TouchInjector.InjectTouchInput(1, new[] { contact });
                                }
                            }
                        }
                    }
                    else
                    {
                        bool bool_d = bool_down_b1 || bool_down_ml || bool_down_mr || bool_down_mm;

                        // Touch Down Simulate
                        if ((bool_down == false) && bool_d)
                        {
                            bool_down = true;
                            pp        = getPos();

                            if (mtype == Mtype.滑鼠右鍵)
                            {
                                bool_m_handled = false;
                            }

                            //模擬觸控-開始
                            contact = MakePointerTouchInfo(pp.X, pp.Y);
                            oFlags  = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                            contact.PointerInfo.PointerFlags = oFlags;
                            bool bIsSuccess = TouchInjector.InjectTouchInput(1, new[] { contact });

                            if (mtype == Mtype.滑鼠右鍵)
                            {
                                Thread.Sleep(1);
                                bool_m_handled = true;
                            }
                        }

                        // Touch Up Simulate
                        if (bool_down && (bool_d == false))
                        {
                            bool_down = false;

                            if (mtype == Mtype.滑鼠右鍵)
                            {
                                bool_m_handled = false;
                            }

                            //模擬觸控-結束
                            contact.PointerInfo.PointerFlags = PointerFlags.UP;
                            TouchInjector.InjectTouchInput(1, new[] { contact });

                            if (mtype == Mtype.滑鼠右鍵)
                            {
                                Thread.Sleep(1);
                                bool_m_handled = true;
                            }
                        }

                        // Touch Move Simulate
                        if (bool_down)
                        {
                            var p2             = getPos();
                            int nMoveIntervalX = (int)((p2.X - pp.X) * f_touch_speed);
                            int nMoveIntervalY = (int)((p2.Y - pp.Y) * f_touch_speed);

                            //模擬觸控-移動
                            contact.Move(nMoveIntervalX, nMoveIntervalY);
                            oFlags = PointerFlags.INRANGE | PointerFlags.INCONTACT | PointerFlags.UPDATE;
                            contact.PointerInfo.PointerFlags = oFlags;
                            TouchInjector.InjectTouchInput(1, new[] { contact });

                            //讓滑鼠跟隨觸控的位置
                            if (f_touch_speed != 1)
                            {
                                NativeMethods.SetCursorPos(pp.X + nMoveIntervalX, pp.Y + nMoveIntervalY);
                                p2 = getPos();
                            }

                            pp = p2;
                            if (overd_sc(pp))  //超出螢幕時自動停止觸控
                            {
                                upFull();
                            }
                        }
                    }


                    Thread.Sleep(11);
                }
            }).Start();


            HookManager.MouseDown += HookManager_MouseDown;
            HookManager.MouseUp   += HookManager_MouseUp;
            //HookManager.MouseMove += HookManager_MouseMove;

            this.FormClosing += Form1_FormClosing;
            init_nIcon();
        }