C# 模拟鼠标事件

来源:互联网 发布:io框架java 编辑:程序博客网 时间:2024/05/04 07:51
        #region 模拟鼠标移动        [DllImport("user32")]        public static extern void SetCursorPos(int x, int y);        #endregion        #region 模拟鼠标单击        private static readonly int MOUSEEVENTF_LEFTDOWN = 0x2;    //鼠标左键down事件        private static readonly int MOUSEEVENTF_LEFTUP = 0x4;    //鼠标左键up事件        [DllImport("user32")]        public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);        #endregion        //获取鼠标在屏幕的坐标        int x = Control.MousePosition.X;        int y = Control.MousePosition.Y;        SetCursorPos(x, y);//模拟鼠标移动        mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);//模拟鼠标左键down         mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);//模拟鼠标左键up


0 0
原创粉丝点击