Пример #1
0
        public sharpAHK.mousePos Mouse(mouse Action, int x = 0, int y = 0, int count = 1)
        {
            sharpAHK.mousePos pos = new sharpAHK.mousePos();

            string button = "Left";
            int    y2     = 0;  // MouseClickDrag
            int    x2     = 0;  // MouseClickDrag
            string speed  = ""; // mousemove / mouseclickdrag / mouseclick
            string R      = ""; // mouseclickdrag


            if (Action == mouse.Click)
            {
                string Command = "Click " + x.ToString() + ", " + y.ToString();
                ahk.Click(Command);
            }

            if (Action == mouse.MouseClick)
            {
                ahk.MouseClick(_AHK.MouseButton.Left, x, y, true, count, speed, _AHK.MouseState.None, false);
            }

            if (Action == mouse.MouseClickDrag)
            {
                ahk.MouseClickDrag(button, x.ToString(), y.ToString(), x2.ToString(), y2.ToString(), speed, R);
            }

            if (Action == mouse.MouseGetPos)
            {
                pos = ahk.MouseGetPos("");
            }

            if (Action == mouse.MouseMove)
            {
                bool OffSetFromCurrentPos = false;
                ahk.MouseMove(x, y, true, speed.ToInt(), OffSetFromCurrentPos);
            }

            return(pos);
        }
Пример #2
0
        /// <summary>Retrieves the current position of the mouse cursor, and optionally which window and control it is hovering over.</summary>
        /// <param name="Opt">BLANK or 1 Populate ControlClassNN, 2 and 3 Populate ControlHwnd | 1: Uses a simpler method to determine OutputVarControl. This method correctly retrieves the active/topmost child window of an Multiple Document Interface (MDI) application such as SysEdit or TextPad. However, it is less accurate for other purposes such as detecting controls inside a GroupBox control. | 2: Stores the control's HWND in OutputVarControl rather than the control's ClassNN. | 3: A combination of 1 and 2 </param>
        public mousePos MouseGetPos(string Opt = "")
        {
            string mouseCoodMode = MouseCoordMode();                                      // store the current mouse mode value

            MouseCoordMode("Relative");                                                   // sets mouse coodinates relative to active window
            string AHKLine = "MouseGetPos, OutXPos, OutYPos, OutWin, OutControl, " + Opt; // ahk line to execute

            ErrorLog_Setup(true);                                                         // ErrorLevel Detection Enabled for this function in AHK
            Execute(AHKLine);                                                             // execute AHK code and return variable value

            //return value from ahk session
            string OutXPos = GetVar("OutXPos");
            string OutYPos = GetVar("OutYPos");

            // populate object to return values to user
            mousePos mouseP = new mousePos();

            mouseP.X_Window = Int32.Parse(OutXPos);
            mouseP.Y_Window = Int32.Parse(OutYPos);
            mouseP.WinHwnd  = GetVar("OutWin");


            MouseCoordMode("Screen");                                              // sets mouse coodinates relative to screen
            AHKLine = "MouseGetPos, OutXPos, OutYPos, OutWin, OutControl, " + Opt; // ahk line to execute
            ErrorLog_Setup(true);                                                  // ErrorLevel Detection Enabled for this function in AHK
            Execute(AHKLine);                                                      // execute AHK code and return variable value

            //return value from ahk session
            OutXPos = GetVar("OutXPos");
            OutYPos = GetVar("OutYPos");

            // populate object to return values to user
            mouseP.X_Screen = Int32.Parse(OutXPos);
            mouseP.Y_Screen = Int32.Parse(OutYPos);

            if (mouseP.WinHwnd == "" || mouseP.WinHwnd == null)
            {
                mouseP.WinHwnd = GetVar("OutWin");
            }


            if (Opt == "" || Opt == "1")
            {
                mouseP.ControlClassNN = GetVar("OutControl");
            }

            if (Opt == "2" || Opt == "3")
            {
                mouseP.ControlHwnd = GetVar("OutControl");
            }

            return(mouseP);



            // v1 ToDo

            /*
             *      //==== Get Mouse Pos =============
             *      //EX:
             *      //  var MousePos = ahk.GetMousePos();
             *      //  string MouseX = MousePos.XPos.ToString();
             *      //  string MouseY = MousePos.YPos.ToString();
             *
             *      public wInfo _GetMousePos()  // gets the current mouse position, returns wInfo object populated
             *      {
             *          wInfo MousePos = new wInfo();
             *          MousePos.MouseXPos = Cursor.Position.X;
             *          MousePos.MouseYPos = Cursor.Position.Y;
             *
             *          return MousePos;
             *      }
             */

            // v2 ToDo

            /*
             *      public wInfo _MouseGetPos()  // gets the current mouse position, returns wInfo object populated (includes control info/handles)
             *      {
             *          if (ahkGlobal.ahkdll == null) { ahkGlobal.ahkdll = new AutoHotkey.Interop.AutoHotkeyEngine(); }
             *          var ahkdll = ahkGlobal.ahkdll;
             *
             *          wInfo mouseInfo = new wInfo();
             *
             *          //ahkdll.SetVar("OutputVar", "");
             *          string Command = "MouseGetPos, MouseX, MouseY, WinID, ControlID, 3";
             *          ahkdll.ExecRaw(Command);
             *
             *          mouseInfo.MouseXPos = Int32.Parse(ahkdll.GetVar("MouseX"));
             *          mouseInfo.MouseYPos = Int32.Parse(ahkdll.GetVar("MouseY"));
             *
             *          // convert string to IntPtr
             *          string WinHwnd = ahkdll.GetVar("WinID");
             *          if (WinHwnd != "")
             *          {
             *              int WinID = Int32.Parse(WinHwnd);  // string to int
             *              mouseInfo.WinHwnd = _ToIntPtr(WinID);  // int to IntPtr
             *          }
             *
             *          // convert string to IntPtr
             *          string ControlHwnd = ahkdll.GetVar("ControlID");
             *          if (ControlHwnd != "")
             *          {
             *              int cID = Int32.Parse(ControlHwnd);  // string to int
             *              mouseInfo.ControlHwnd = _ToIntPtr(cID);  // int to IntPtr
             *          }
             *
             *          //MsgBox("X=" + mouseInfo.MouseXPos.ToString());
             *          //MsgBox("Y=" + mouseInfo.MouseYPos.ToString());
             *          //MsgBox("WinHwnd=" + mouseInfo.WinHwnd.ToString());
             *          //MsgBox("ControlHwnd=" + mouseInfo.ControlHwnd.ToString());
             *
             *          _ControlGetPos(null, mouseInfo.ControlHwnd);
             *
             *
             *          return mouseInfo;
             *      }
             */
        }