1
我正在使用Vb2010和Windows 7
我試圖創建一個程序,點擊另一個進程,但我有一些左,右擊事件的麻煩。
事實上,當我正確,然後左鍵單擊時,鼠標會表現得很奇怪:左鍵和右鍵單擊似乎會交換,因爲左鍵單擊將打開菜單,右鍵單擊不會執行任何操作。
使其恢復正常的唯一方法是物理上正確然後左鍵單擊,但我需要程序自動執行此操作。有沒有解決方法或解決方法?謝謝。鼠標事件點擊後奇怪的鼠標行爲
要重新創建此問題,您可以在vb.net中創建一個帶有button1的表單並粘貼此代碼(然後運行調試並單擊該按鈕),或者可以從here下載已編譯的程序。
Public Class Form1
Private Declare Sub mouse_event Lib "user32" (ByVal dwflags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cbuttons As Integer, ByVal dwextrainfo As Integer)
Private Const mouseclickdown = 2
Private Const mouseclickup = 4
Private Const rightclickdown = 8
Private Const rightclickup = 10
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
System.Threading.Thread.Sleep(200)
Cursor.Position = New Point(650, 350)
System.Threading.Thread.Sleep(200)
mouse_event(rightclickdown, 0, 0, 0, 0)
System.Threading.Thread.Sleep(200)
mouse_event(rightclickup, 0, 0, 0, 0)
System.Threading.Thread.Sleep(200)
Cursor.Position = New Point(500, 200)
System.Threading.Thread.Sleep(200)
mouse_event(mouseclickdown, 0, 0, 0, 0)
System.Threading.Thread.Sleep(200)
mouse_event(mouseclickup, 0, 0, 0, 0)
System.Threading.Thread.Sleep(200)
End Sub
End Class
非常感謝你,這是一個愚蠢的錯誤,但給了我很多麻煩。再次感謝你 :) – user3723902