2
votes

I'm looking for a simple way of setting the cursor position by script, after computer start.

I've found :

Private Declare Sub SetCursorPos Lib "User32" (ByVal X As Long, ByVal Y As Long)
SetCursorPos 4, 52

But can't manage to use them in a VBScript for example...

Is there a better solution ? How can I do this without having to compile an application ?

Thanks in advance for your help !

3

3 Answers

2
votes

No, unfortunately you cannot call Windows API functions directly from VBScript. Given the security implications of a scripting language calling down to native code directly, and the lack of any data types other than Variant, there's no way this can work.

One way to do it is to create some kind of helper automation object to call the API, which you can then use from VBScript.

But that's an awful lot of work for a one-off task. I'd suggest just compiling an application in whatever language you're comfortable in. If you can write in VBScript, you can write in VB 6...if you can still find a copy of the compiler/IDE.

0
votes

You need to define setCursorPos

VBS-Helper (Posted at 15:09 GMT)

-1
votes

This is a excel code, this is working. Try it in vbscript only!

Dim Excel: Set Excel = WScript.CreateObject("Excel.Application")
Excel.ExecuteExcel4Macro "CALL(""user32"",""SetCursorPos"",""JJJ""," & 320 & "," & 2 & ")"