日期:2014-05-18 浏览次数:21126 次
[DllImport("user32.dll")]
private static extern void mouse_event
(
UInt32 dwFlags, // motion and click options
UInt32 dx, // horizontal position or change
UInt32 dy, // vertical position or change
UInt32 dwData, // wheel movement
IntPtr dwExtraInfo // application-defined information
);
private const UInt32 MOUSEEVENTF_LEFTDOWN = 0x0002;
private const UInt32 MOUSEEVENTF_LEFTUP = 0x0004;
public void Click()
{
m_Browser.Visible = true;
Point pp = new Point(CurrentTask.X, CurrentTask.Y);
Point screenPoint = m_MainForm.PointToScreen(pp);
screenPoint.X += m_Browser.Left;
screenPoint.Y += m_Browser.Top;
Cursor.Position = screenPoint;
mouse_event(MOUSEEVENTF_LEFTDOWN, (UInt32)pp.X, (UInt32)pp.Y, 0, new IntPtr());
for (int i = 0; i < 19; i++)
{
Thread.Sleep(20);
Application.DoEvents();
}
mouse_event(MOUSEEVENTF_LEFTUP, (UInt32)pp.X, (UInt32)pp.Y, 0, new IntPtr());
m_Browser.Visible = false;
m_State = ClickerState.Clicked;
m_CurrentTask = null;
Thread.Sleep(100);
//The element the browser clicked is not a link
if(m_State != ClickerState.Navigating)
{
m_State = ClickerState.WaitingTask;
Navigate(m_Manager.GetTask());
}
}
------解决方案--------------------