Because of the mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, x, y, 0, 0); line mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, x, y, 0, 0); the loop is not executed, what to do?
Here is the whole code:
public Form1() { InitializeComponent(); } [DllImport("user32.dll")] static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo); private const int MOUSEEVENTF_MOVE = 0x0001; private const int MOUSEEVENTF_LEFTDOWN = 0x0002; private const int MOUSEEVENTF_LEFTUP = 0x0004; private const int MOUSEEVENTF_RIGHTDOWN = 0x0008; private const int MOUSEEVENTF_RIGHTUP = 0x0010; private const int MOUSEEVENTF_MIDDLEDOWN = 0x0020; private const int MOUSEEVENTF_MIDDLEUP = 0x0040; private const int MOUSEEVENTF_ABSOLUTE = 0x8000; private void button1_Click(object sender, EventArgs e) { int i = 1; int x = 945; int y = 250; while(i < 10) { MessageBox.Show(""); i++; Cursor.Position = new Point(x,y); y = y + 20; mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, x, y, 0, 0); } }