现在的位置: 首页 > 综合 > 正文

C# 鼠标移动到指定位置,并且单击

2013年12月15日 ⁄ 综合 ⁄ 共 807字 ⁄ 字号 评论关闭

        [DllImport("User32")]
        public extern static void mouse_event(int dwFlags, int dx, int dy, int dwData, IntPtr dwExtraInfo);

        [DllImport("user32.dll")] 
       static extern bool SetCursorPos(int X, int Y); 

        public enum MouseEventFlags
        {
            Move = 0x0001,
            LeftDown = 0x0002,
            LeftUp = 0x0004,
            RightDown = 0x0008,
            RightUp = 0x0010,
            MiddleDown = 0x0020,
            MiddleUp = 0x0040,
            Wheel = 0x0800,
            Absolute = 0x8000
        }   

 private void button3_Click(object sender, EventArgs e)
        {

               SetCursorPos(607, 385);//用屏幕取点工具可以得到坐标
               mouse_event((int)(MouseEventFlags.LeftDown | MouseEventFlags.Absolute), 607, 385, 0, IntPtr.Zero);
               mouse_event((int)(MouseEventFlags.LeftUp | MouseEventFlags.Absolute), 607, 385, 0, IntPtr.Zero);

}

 

抱歉!评论已关闭.