我在我的UserControl中有圖像的ListView。當我帶來的圖片,我是重新繪製圖片時,從圖像圖片中刪除鼠標滋養舊。 但是,當我在同一張圖片上再次拍攝時不想重畫,但是當我帶走ListView的教堂並再次使用navozhu時,它會起作用。我以爲我可以製造一隻模仿老鼠。或者告訴我更好的東西。模擬鼠標移動
[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);
它的工作,但我看到了一絲老鼠。
我在我的UserControl中有圖像的ListView。當我帶來的圖片,我是重新繪製圖片時,從圖像圖片中刪除鼠標滋養舊。 但是,當我在同一張圖片上再次拍攝時不想重畫,但是當我帶走ListView的教堂並再次使用navozhu時,它會起作用。我以爲我可以製造一隻模仿老鼠。或者告訴我更好的東西。模擬鼠標移動
[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);
它的工作,但我看到了一絲老鼠。
爲了模擬鼠標移動,按鈕的點擊等,您可以嘗試mouse_event
API函數。
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646260(v=vs.85).aspx
[DllImport("User32.dll",
EntryPoint = "mouse_event",
CallingConvention = CallingConvention.Winapi)]
internal static extern void Mouse_Event(int dwFlags,
int dx,
int dy,
int dwData,
int dwExtraInfo);
[DllImport("User32.dll",
EntryPoint = "GetSystemMetrics",
CallingConvention = CallingConvention.Winapi)]
internal static extern int InternalGetSystemMetrics(int value);
...
// Move mouse cursor to an absolute position to_x, to_y and make left button click:
int to_x = 500;
int to_y = 300;
int screenWidth = InternalGetSystemMetrics(0);
int screenHeight = InternalGetSystemMetrics(1);
// Mickey X coordinate
int mic_x = (int) System.Math.Round(to_x * 65536.0/screenWidth);
// Mickey Y coordinate
int mic_y = (int) System.Math.Round(to_y * 65536.0/screenHeight);
// 0x0001 | 0x8000: Move + Absolute position
Mouse_Event(0x0001 | 0x8000, mic_x, mic_y, 0, 0);
// 0x0002: Left button down
Mouse_Event(0x0002, mic_x, mic_y, 0, 0);
// 0x0004: Left button up
Mouse_Event(0x0004, mic_x, mic_y, 0, 0);
鼠標Mickeys?米老鼠?真的嗎? – KingCronus
API函數「mouse_event」在虛擬65536x65536屏幕上運行。這個屏幕上的座標稱爲mickey - 可能是在米老鼠之後:)。例如。 (引自MSDN)「......一隻老鼠必須移動的量......」。 –
謝謝。但我怎樣才能讓鼠標繼續Forme只是一個開始UTB x = 0 y = 0,然後我把例子x = 50 y = 50 – guxago
「使畫面」=拖放:小心,它米奇不像素作品? 「滋養」是什麼意思? 「教堂」「navozhu」? – Rup
我猜如果他知道他不會使用谷歌翻譯。 – AlexDev