VBS sendkeys simulated key operation Solution

Source: Internet
Author: User

Copy codeThe Code is as follows: '==============================================
'Sendkeys in VBS simulate keyboard keys
'2013-26
'Liu Lin
'==============================================
Dim WshShell
Set WshShell = WScript. CreateObject ("WScript. Shell ")
WshShell. Run "cmd"
'Wait the script for 1000 milliseconds, that is, 1 second before executing the next statement.
WScript. Sleep 1000
'-- When sending characters, the input method must be in the English File status
'Send a semicolon
WshShell. SendKeys ";"
WScript. Sleep 1000
'Send colons
WshShell. SendKeys ":"
WScript. Sleep 1000
'Send double quotation marks -- use chr to convert double quotation marks
WshShell. SendKeys Chr (34)
WScript. Sleep 1000
'Send a string with double quotation marks
WshShell. SendKeys Chr (34) & "this is a string" & Chr (34)
WScript. Sleep 1000
'-- Remember, this is a simulated key operation, so it cannot send Chinese characters.
'Wshshell. SendKeys Chr (34) & "this is a string" & Chr (34)
WScript. Sleep 1000
'================================================ ==========
'-- How do I simulate the carriage return, the top key, and the Alt key?
'================================================ ==========
'-- How to simulate carriage return, -- {enter} indicates that the carriage return is sent.
WshShell. SendKeys "this is a enter! {Enter }"
WScript. Sleep 1000
'-- How to simulate Shift, -- + indicates sending shift
WshShell. SendKeys "this is + a" 'returns this is
WScript. Sleep 1000
'-- How to simulate Alt, -- % indicates sending Alt
WshShell. SendKeys "this is % {TAB}" 'returns a window for switching.
WScript. Sleep 1000
'================================================ ================================
'-- How to send %, + ^
WshShell. SendKeys "this is {+} {^} {%}" 'results in a switching window
WScript. Sleep 1000
'-- Here you may already understand. Put it in {} when sending special characters
'================================================ ================================
'==============================================
'For more information, see VBS help documentation
'==============================================

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.