开发者

VBS Click Position

Is there a way to make a VBScript click in an exact position of your screen like (10,100) or somthin开发者_如何学运维g along those lines? Or perhaps click over a text box?


VBScript, by itself, isn't aware of the desktop or any other windows. Through the use of various COM/ActiveX objects, you can interact with other processes and windows, though. For example, you can create a shortcut on the desktop, start a program, automate a series of keystrokes, or force a program to come to the front.

As far as automating mouse movements or mouse clicks, you would probably need to write your own COM object that can do this. A combination of the SetCursorPos and SendInput API calls could accomplish this.

Google Answers has some example C++ code that can accomplish this. Planet Source Code has some example VB6 code that can accomplish this.

From there, you can create your COM/ActiveX objects that will allow you to use VBScript to click where you want.


This will move the cursor:

Option Explicit
Dim Excel, x, y

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

x = "500"
y = "222"
Excel.ExecuteExcel4Macro ( _
    "CALL(""user32"",""SetCursorPos"",""JJJ""," & x & "," & y & ")")

WScript.Sleep (100)
WScript.Echo "Program Ended"


The code below can be used to move your mouse to x,y coords 100,100

Set DeviceReplay = CreateObject("Mercury.DeviceReplay")

DeviceReplay.MouseMove 100,100
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜