我正在使用C#,框架4(32位)的Windows窗體應用程序。將鼠標移動到位置並點擊左鍵
我有一個包含鼠標的座標的列表,我可以捕獲它們。到現在爲止還挺好。
但是在某個時候,我想去那些座標並且點擊鼠標左鍵。
這是怎麼看起來像現在:
for (int i = 0; i < coordsX.Count; i++)
{
Cursor.Position = new Point(coordsX[i], coordsY[i]);
Application.DoEvents();
Clicking.SendClick();
}
而且點擊類:
class Clicking
{
private const UInt32 MOUSEEVENTF_LEFTDOWN = 0x0002;
private const UInt32 MOUSEEVENTF_LEFTUP = 0x0004;
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
);
// public static void SendClick(Point location)
public static void SendClick()
{
// Cursor.Position = location;
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr());
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr());
}
}
但我發現了這個錯誤:
Could not load type 'program.Clicking' from assembly 'program, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because the method 'mouse_event' has no implementation (no RVA).
而且我真的不明白問題是什麼......你們知道問題是什麼嗎?或者你知道一個更好的方法來做我想做的事嗎?
我將該行插入到點擊類中,但仍然出現相同的錯誤 – Mathlight
您是否刪除了對'mouse_event'的刪除?確保你這樣做,並用此替換它。 – Serdalis
那sendinput將如何特別適用於我的問題?因爲我對此很感興趣,並且我不知道是否需要鏈接中的所有代碼... – Mathlight