none
C#,控制鼠标在屏幕的特定位置每隔特定时间就点击一次 RRS feed

答案

  •  

    你可以这样处理

    1.根据屏幕分辨率计算你要点击的位置

    2.利用API函数来实现鼠标点击

    参照

    http://www.cnblogs.com/longle/archive/2011/06/04/2072915.html

    public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            [DllImport("User32")]
            public extern static void mouse_event(int dwFlags, int dx, int dy, int dwData, IntPtr dwExtraInfo);
    
            [DllImport("User32")]
            public extern static void SetCursorPos(int x, int y);
    
            [DllImport("User32")]
            public extern static bool GetCursorPos(out POINT p);
    
            [StructLayout(LayoutKind.Sequential)]
            public struct POINT
            {
                public int X;
                public 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 AutoClick(int x, int y)
            {
                POINT p = new POINT();
                GetCursorPos(out p);
                try
                {
                    SetCursorPos(x, y);
                    mouse_event((int)(MouseEventFlags.LeftDown | MouseEventFlags.Absolute), 0, 0, 0, IntPtr.Zero);
                    mouse_event((int)(MouseEventFlags.LeftUp | MouseEventFlags.Absolute), 0, 0, 0, IntPtr.Zero);
                }
                finally
                {
                    SetCursorPos(p.X, p.Y);
                }
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                AutoClick(20, 40);
            }
        }
    
    

     


    http://blog.csdn.net/zx13525079024
    2011年11月18日 2:12