如何将鼠标事件传递给webbrowser控件(让用户通过鼠标控制)

时间:2015-02-19 05:44:54

标签: vb.net multithreading mouse

我有一些相当混乱的代码来自动化一些在线流程。将值输入字段相当容易;

Dim element As HtmlElement = webbrow.Document.GetElementById("inputy")
                    If element IsNot Nothing Then
                        element.InnerText =y.ToString
                    End If

我甚至找到了一些点击不接受 InvokeMember(“点击”)的元素的工作方法;

Public Declare Auto Function SetCursorPos Lib "User32.dll" (ByVal X As Integer, ByVal Y As Integer) As Long
Public Declare Auto Function GetCursorPos Lib "User32.dll" (ByRef lpPoint As Point) As Long
Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Public Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down
Public Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up
Public Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
Public Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up

 SetCursorPos(976, 329)
 mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
 mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)

然而,上面的代码有效地接管了鼠标并改变了窗口中光标的位置。我想要一种方法,我可以告诉第三方程序或webbrowser控件,我已经在给定位置点击而不控制鼠标。基本上我希望能够在鼠标点击发生时使用计算机。

0 个答案:

没有答案