3
votes

Is there a way to make a VBScript click in an exact position of your screen like (10,100) or somthing along those lines? Or perhaps click over a text box?

3
Hi. If you find an answer helpful, you can click the up vote buttons to the left of the answer, and if the answer was the one you wanted, you can click the big tick to accept. Most forums and sites that give answers have something of this sort, and it is usually a good idea to use these rating systems. - Fionnuala

3 Answers

5
votes

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.

3
votes

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"
0
votes

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