Visual Basic Script (VBS) input help

How to move mouse and click with mouse and hold a keyboard button for the specified amout in vbs script?

What is vbs script? Can you please send a link to your Repl?

VBS is Visual Basic Script, it’s a scripting language that to my knowledge became infamous for frequently being used for viruses.

3 Likes

My VBS is really rusty so not sure I remember correctly, but maybe it helps

Set objShell = WScript.CreateObject("WScript.Shell")
Set objShellApp = CreateObject("Shell.Application")
Set objIE = objShellApp.Windows.Item(0)

' Move the mouse to x and y
objShell.Run "cmd /c nircmd.exe movecursor [X] [Y]", 0, True

'  left mouse button
objIE.Document.parentWindow.execScript "document.elementFromPoint([X], [Y]).click();", "JavaScript"

' Hold down  keyboard button for time
objShell.SendKeys "{[Keyboard Button]}"
WScript.Sleep [Time in Milliseconds]
objShell.SendKeys "{[Keyboard Button]}"

Hope this helps. Just grabbed from an old git I had, but I abandoned VBS ages ago and was never any good at it

5 Likes

I don’t think you did the long press keyboard button right because all it does is presses the button waits then presses it again

It could well be. As i wrote I abandon VBS ages ago. Sorry if does not help.

also do you know how to make a function in it?

1 Like

Is that not sometime like

Function AddNumbers(num1, num2)
   AddNumbers = num1 + num2
End Function

ok thanks for telling me that too

For long key press i think you need to send the press command, sleep and press up. Or something like that. I am pretty sure that in sleep the key stays pressed till you do send the up.
But again was long ago.

sorry about that this is the error i am getting with my code:
image

also can you send me the link to that git?

here is all of my code :
image
sorry about the cut off move mouse

Sorry but that is a private git (nit GitHub) on my NAS’s.

Should you not concatenate strings with & instead of +?

Send me what the code looks like now then if you say that’s how you do it

Also I believe that doesn’t work as I tried running that command through cmd prompt typing “/c nircmd.exe movecursor [5] [10]” and it doesn’t understand the command /c