Using VBS to implement a small keyboard action Ctrl + V paste operation and thinking analysis _vbs

Source: Internet
Author: User
Tags chr sleep
Tips:
1, every time you have to jump out of the window in 1.8 seconds after this action, and is only sent once the action, sent after the next window to wait to jump out of the cycle.
2, each loop will only send a CTRL + V after the stop, rather than always send

When you see the problem, start writing the test code immediately, and the problem occurs:

When the InputBox window pops up, the VBS is paused, waits for user input, clicks OK or cancels,

So the Wshshell.sendkeys "^v" behind it will not execute,

If you click OK or Cancel before the InputBox window pops up, then CTRL + + will not be able to paste the contents of the Clipboard into the InputBox window, if the Wshshell.sendkeys "^v" before the InputBox, also not, because For InputBox has not yet bounced out, Ctrl + V can not implement paste content to InputBox,

To convert the idea, we write InputBox and sendkey two files so that they do not conflict with each other, the final resolution code is as follows:
Copy Code code as follows:

Set wshshell=wscript.createobject ("Wscript.Shell")
Wscript.Sleep 2000
Set fso=wscript.createobject ("Scripting.FileSystemObject")
Set F=fso.opentextfile ("Sendkey.vbs", 2,true)
F.write ("Set wshshell=wscript.createobject (" & Chr () & "Wscript.Shell" & Chr (+) & ")"
F.writeblanklines (1)
F.write ("Wscript.Sleep 1800")
F.writeblanklines (1)
F.write ("Wshshell.appactivate" & Chr () & "Tips" & Chr (34))
F.writeblanklines (1)
F.write ("Wshshell.sendkeys" & Chr () & "^v" & Chr (34))
F.writeblanklines (1)
F.close
Wshshell.run ("Sendkey.vbs")
InputBox "Please enter", "Prompt", "" "
Fso. DeleteFile ("Sendkey.vbs")

The code first writes Sendkey.vbs and executes, waits 1.8 seconds to send Ctrl + V, then pops up the InputBox, then InputBox bounces out, Sendkey.vbs waits 1.8 seconds to execute CTRL + V Paste the content into the InputBox input box. Problem solving

Summary: In the face of some problems, can not be a dead man, change the train of thought, in fact, not difficult to solve!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.