winform模拟鼠标点击

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Giser_D/article/details/83149624
        //绑定事件 导入dll
        [System.Runtime.InteropServices.DllImport("user32")]
        private static extern int mouse_event(int mouseevent, int dx, int dy, int cButtons, int dwExtraInfo);
        [DllImport("User32")]
        public extern static void SetCursorPos(int x, int y);  


        private void button2_Click(object sender, EventArgs e)
        {
            //移动鼠标 
            const int MOUSEEVENTF_MOVE = 0x0001;
            //模拟鼠标左键按下 
            const int MOUSEEVENTF_LEFTDOWN = 0x0002;
            //模拟鼠标左键抬起 
            const int MOUSEEVENTF_LEFTUP = 0x0004;
            //模拟鼠标右键按下 
            const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
            //模拟鼠标右键抬起 
            const int MOUSEEVENTF_RIGHTUP = 0x0010;
            //模拟鼠标中键按下 
            const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;
            //模拟鼠标中键抬起 
            const int MOUSEEVENTF_MIDDLEUP = 0x0040;
            //标示是否采用绝对坐标 
            const int MOUSEEVENTF_ABSOLUTE = 0x8000;

            SetCursorPos(40, 65);  //设置鼠标放的位置

            //连续两次点击--
            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
        } 

猜你喜欢

转载自blog.csdn.net/Giser_D/article/details/83149624

相关文章