-2

I have found the below vbscript code that will move the mouse cursor to a particular location but I also need it to make one click wherever the cursor is at on the screen.

I need this to be done only with vbscript because the systems constraints imply so. My current code:

Option Explicit
Dim Excel, x, y

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

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

WScript.Sleep (100)
bitoiu
  • 6,893
  • 5
  • 38
  • 60
ManiMagnet
  • 1
  • 1
  • 1
  • 1
    Why are you trying to use Excel for that? That´s like using a nuclear device to light a cigarette. – TheBlastOne Apr 04 '14 at 06:05
  • Because I don't know any another way around.. – ManiMagnet Apr 06 '14 at 18:55
  • Any Help would be appreciated – ManiMagnet Apr 06 '14 at 19:00
  • I made an answer out of my comments. If the answer is helpful, please accept it. This will remove this question out of the list of open questions. Otherwise, comment on it why it´s not helpful. – TheBlastOne Apr 08 '14 at 07:41
  • I still didn't get your answer. I won't use excel but there must be something else I can use to make it work. The only thing I need is a VBscript code to make one click wherever (probably in center) on the screen. Please help. I needed it badly and tried lot of google things but no help. – ManiMagnet Apr 11 '14 at 09:41
  • It´s a WINAPI interfacing job. Without additional software (development tool, or stuff like AutoIt), the only thing that comes to mind is RunDLL. Google that. And learn about WinAPI details. I don´t have them all handy. And I doubt that the calls you need are callable via rundll. – TheBlastOne Apr 14 '14 at 10:01

1 Answers1

0

Your restriction is quite limiting, see Import WinAPI Function in *.VBS File.

And it would be news to me if you could use CALL to call a WinAPI function. CALL only calls VBScript functions.

There is a good COM integration in VBS (CreateObject...). But if you can´t locate a COM object that does what you want (and still can´t write our own), you might have a hard time achieving your goal without additional software. For which Excel would be one of the worse choices since it´s big, and its VBA is similarily limited as VBS regarding native OS calls.

You could use rundll to call certain WinAPI functions by calling the entry points in the windows DLLs. Some of them might deliver what you need. But see How to use Rundll32 to execute DLL Function? for the mess that you would be facing :-) I think you should get AutoIt authorized, see autoitscript.com/site/autoit.

Then, stuff like what you want is a snap.

Community
  • 1
  • 1
TheBlastOne
  • 4,291
  • 3
  • 38
  • 72