Use vbs to implement a keypad Ctrl + V paste operation and Train of Thought Analysis

Source: Internet
Author: User

Tip:
1. This action is triggered every 1.8 seconds after a window exists, and only one action is sent. Wait for the next window to jump out and recycle.
2. In each loop, only Ctrl + V is sent and then stopped, instead of sending it all the time.

When you see the problem, start writing the test now.CodeAt this time, the problem occurs:

After the inputbox window pops up, the vbs is paused. Wait for the user to enter the box and click OK or cancel,

So wshshell. sendkeys "^ V" after it cannot be executed,

If you click OK or cancel after the inputbox window pops up, you cannot paste the content in the clipboard into the inputbox window by pressing CTRL + v. sendkeys "^ V" won't work if it is placed before inputbox, because inputbox hasn't been popped up, And Ctrl + V cannot paste the content to inputbox,

In this way, we write inputbox and sendKey into two files so that they do not conflict with each other. The final solution code is as follows:Copy codeThe Code is 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 (34) & "wscript. Shell" & CHR (34 )&")")
F. writeblanklines (1)
F. Write ("wscript. Sleep 1800 ")
F. writeblanklines (1)
F. Write ("wshshell. appactivate" & CHR (34) & "prompt" & CHR (34 ))
F. writeblanklines (1)
F. Write ("wshshell. sendkeys" & CHR (34) & "^ V" & CHR (34 ))
F. writeblanklines (1)
F. Close
Wshshell. Run ("sendKey. vbs ")
Inputbox "enter", "prompt ",""
FSO. deletefile ("sendKey. vbs ")

The code first writes sendKey. run the vbs command and wait for 1.8 seconds to send Ctrl + V. Then, inputbox is displayed. At this time, inputbox is displayed, and sendKey is displayed. after waiting for 1.8 seconds, vbs also runs Ctrl + V to paste the content into the inputbox input box. problem Solving

conclusion: When you encounter some problems, it is not difficult to solve them!

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.