Reputation: 21
I am quite new to VBScript and I'm looking to learn, so please keep it as simple as possible. (I'm sorry, but I just don't understand many examples provided by others.)
Basically, I'm trying to run
Set wshShell = wscript.CreateObject("WScript.Shell")
do
wscript.sleep 9000
wshshell.sendkeys "2"
loop
(its longer, I've just shortened our parts you don't need to see.)
I want to make it so that when I press the = key it will run the code, activating the keypress of the number 2.
For clarification on the loop part, I want it so that once I press = it will send the key 2 over and over without needing the press of = again.
A stop function would be very handy too!
Upvotes: 2
Views: 7548
Reputation: 74
It could be complicated to wait for a keypress in VBS. First, you need to loop to catch the pressed key, then you have to make annother loop (sleep 9000 and sendkeys "2") and finaly, find a way to stop the loop. There is a example here: Need to sense a keystroke in VBscript to end a loop.
If it's possible I advise you to use a HTA page with two buttons (start loop and stop loop) instead of waiting for a key to be pressed. Here is how to do this: How to stop a loop when pressing "OK" on a message box with VBS?
You need a HTA file (same thing as html but is standalone, not runed from a web browser and the extension is ".hta").
Upvotes: 1