mouseevent - 鼠标事件点击后,奇怪的鼠标行为

  显示原文与译文双语对照的内容
0 0

我正在使用Vb2010和 Windows 7.
我正在尝试创建一个单击另一个进程的程序,但是我对左和右点击事件有点麻烦。
事实上,当我右击然后左键点击时,鼠标会表现得奇怪: 左右点击似乎是交换的,因为左点击将打开菜单,右键单击将不会发生任何事情。
使它回到正常的唯一方法是物理右,然后左击,但是我需要程序自动执行这个操作。 是否有修复或者解决方法? 谢谢。

要重新创建这个问题,你可以在 VB.Net 中创建一个表单,并粘贴这个代码( 然后运行调试并单击按钮),或者从下载。


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

时间: 原作者:

0 0

rightclickup 应该具有 0x0010的值( 源: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646260(v=vs.85).aspx ),十六进制为 10. 十进制,它是 16.


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 = 16

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

...