开发者

How to simulate a mouse click in vb.net

I wants to be able to simulate mouse clicks on a WebBroswer in vb.net (even when the program in not on top, it will run开发者_如何学C in the background) How would I do this? I want it to click on a button every one second in the webBrowser. Any ideas?

Thanks in advance


Warning: This is an awful hack using an Excel 4 macro. It's actually written in VBScript, but if I'm not mistaken the syntax is similar if not identical in .NET. Of course, you need Excel to be installed.

Set Excel = WScript.CreateObject("Excel.Application")

' Where on the screen do you want to click?
i = "111"
j = "222"

Excel.ExecuteExcel4Macro ( _
    "CALL(""user32"",""SetCursorPos"",""JJJ""," & i & "," & j & ")")

WScript.Sleep 100
Excel.Quit
Set Excel = Nothing

Looking forward to more elegant answers!


you will have a limited number of actions, that are valid after clicking. Use a timer and at each timer-tick select one of the actions randomly, numbering them sequentially.


Before you Excel.Quit....

do the following:

WScript.Sleep(100)

The following is like simulation of mouse left click: do a IE focus OR app focus:

'objIE.document.focus()
'myShell.sendkeys ("{enter}")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜