Ejemplo n.º 1
0
        /// <summary>
        /// 鼠标点击
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="option">1:鼠标左键点击,2:鼠标右键点击</param>
        public void MouseClick(int x, int y, int option = 1)
        {
            User32API.SetCursorPos(x, y);//设置鼠标位置(相对于整个桌面);
            Thread.Sleep(100);
            switch (option)
            {
            case 1:
            {
                User32API.MouseEvent(MouseEventType.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
                Thread.Sleep(100);
                User32API.MouseEvent(MouseEventType.MOUSEEVENTF_LEFTUP, x, y, 0, 0);
                Thread.Sleep(100);
                break;
            }

            case 2:
            {
                User32API.MouseEvent(MouseEventType.MOUSEEVENTF_RIGHTDOWN, x, y, 0, 0);
                Thread.Sleep(100);
                User32API.MouseEvent(MouseEventType.MOUSEEVENTF_RIGHTUP, x, y, 0, 0);
                Thread.Sleep(100);
                break;
            }

            default:
                break;
            }
            Thread.Sleep(500);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 鼠标点击
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="index">点击次数</param>
 public void LeftMouseClick(int x, int y, int index = 1)
 {
     User32API.SetCursorPos(x, y);//设置鼠标位置(相对于整个桌面);
     Thread.Sleep(100);
     for (int i = 0; i < index; i++)
     {
         User32API.MouseEvent(MouseEventType.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
         Thread.Sleep(100);
         User32API.MouseEvent(MouseEventType.MOUSEEVENTF_LEFTUP, x, y, 0, 0);
         Thread.Sleep(100);
     }
 }