VBScript SendKeys Instance Code encyclopedia _vbs

Source: Internet
Author: User

The format used is: Object. SendKeys string

"Object": Represents the WshShell object
"String": Represents the key command string to be sent, which needs to be placed in double quotes in English.

1. Basic key

In general, the key commands to be sent can be represented directly by the key character itself, such as sending the letter "X" and using "Wshshell.sendkeys" X "". Of course, can also send multiple key commands directly, only to the key characters in order, for example, to send the key "Happy", you can use the "Wshshell.sendkeys" Happy "".

2. Special function keys

For keys that need to be combined with the shift, Ctrl, alt three control keys, SendKeys uses special characters to indicate:

Shift---------Wshshell.sendkeys "+"
Ctrl---------Wshshell.sendkeys "^"
Alt---------Wshshell.sendkeys "%"

How do you represent these keys because the characters "+" and "^" are used to represent special control buttons?

Just enclose these characters in curly braces. For example:

To send a plus "+", you can use the "Wshshell.sendkeys" {+} ""

In addition, for some control functions that do not generate characters, you also need to use the curly braces around the key to the name, such as to send enter, you need to use "Wshshell.sendkeys" {ENTER} "" ", send the downward arrow key with" Wshshell.sendkeys " {down} "" indicates.

Space---------Wshshell.sendkeys ""
Enter---------Wshshell.sendkeys "{Enter}"
←---------Wshshell.sendkeys "{right}"
↑---------Wshshell.sendkeys "{Up}"
F1---------Wshshell.sendkeys "{F1}"

Tips: If you need to send multiple, repetitive, single-letter keystrokes, you don't have to type the letter repeatedly, SendKeys allows you to use a simplified format for the description, using the format "{Key number}". For example, to send a 10 letter "x", enter "Wshshell.sendkeys" {x 10} "".

Instance:
----------------------------------------------------
Press F5 to refresh the desktop

Dim Wshshell,path,i
Set WshShell = WScript.CreateObject ("Wscript.Shell")
Wshshell.sendkeys "{F5}"
----------------------------------------------------
automatic restart of the computer

Set WshShell = CreateObject ("Wscript.Shell")
Wshshell.sendkeys "^{esc}u"
Wshshell.sendkeys "R"
----------------------------------------------------
Start Task Manager

Set WshShell = CreateObject ("Wscript.Shell")
Wshshell.sendkeys "^+{esc}"
----------------------------------------------------
QQ Message Mass

Dim WshShell
Set wshshell= wscript.createobject ("Wscript.Shell")
Wshshell.appactivate "Bomb"
For I=1 to 60
Wscript.Sleep 800
Wshshell.sendkeys "Number0"
Wshshell.sendkeys I
Wshshell.sendkeys '%s '
Next
----------------------------------------------------
Automatic to Baidu Search song: white flag

Dim Wshshell,path,i
Set WshShell = WScript.CreateObject ("Wscript.Shell")
Wshshell.run ("IEXPLORE.") EXE ")
Wscript.Sleep 2000
Wshshell.appactivate "About:blank-microsoft Internet Explorer"
Wshshell.sendkeys "+{tab}"
Wshshell.sendkeys "Http://mp3.baidu.com"
Wscript.Sleep 800
Wshshell.sendkeys ' {ENTER} '
Wscript.Sleep 3000
Wshshell.sendkeys "White flag"
Wscript.Sleep 800
Wshshell.sendkeys ' {ENTER} '
----------------------------------------------------
Enter Happy birthday! in Notepad and save as Birth.txt

Dim WshShell
Set wshshell=wscript.createobject ("Wscript.Shell")
Wshshell.run "Notepad"
Wscript.Sleep 1500
Wshshell.appactivate "Untitled-Notepad"
Wshshell.sendkeys "H"
Wscript.Sleep 500
Wshshell.sendkeys "a"
Wscript.Sleep 500
Wshshell.sendkeys "P"
Wscript.Sleep 500
Wshshell.sendkeys "P"
Wscript.Sleep 500
Wshshell.sendkeys "Y"
Wscript.Sleep 500
Wshshell.sendkeys ""
Wscript.Sleep 500
Wshshell.sendkeys "B"
Wscript.Sleep 500
Wshshell.sendkeys "I"
Wscript.Sleep 500
Wshshell.sendkeys "R"
Wscript.Sleep 500
Wshshell.sendkeys "T"
Wscript.Sleep 500
Wshshell.sendkeys "H"
Wscript.Sleep 500
Wshshell.sendkeys "D"
Wscript.Sleep 500
Wshshell.sendkeys "a"
Wscript.Sleep 500
Wshshell.sendkeys "Y"
Wscript.Sleep 500
Wshshell.sendkeys "!"
Wscript.Sleep 500
Wshshell.sendkeys "%fs"
Wscript.Sleep 500
Wshshell.sendkeys "B"
Wscript.Sleep 500
Wshshell.sendkeys "I"
Wscript.Sleep 500
Wshshell.sendkeys "R"
Wscript.Sleep 500
Wshshell.sendkeys "T"
Wscript.Sleep 500
Wshshell.sendkeys "H"
Wscript.Sleep 500
Wshshell.sendkeys '%s '
Wscript.Sleep 500
Wshshell.sendkeys "%fx"
----------------------------------------------------
make a notepad that can be saved automatically and regularly

' The first part: defining Variables and Objects

Dim WshShell, Autosavetime, Txtfilename
autosavetime=300000
Set wshshell=wscript.createobject ("Wscript.Shell")
Txtfilename=inputbox ("Please enter the name of the file you want to create (not in Chinese and plain numbers):"

' Part Two: open and activate Notepad

Wshshell.run "Notepad"
Wscript.Sleep 200
Wshshell.appactivate "Untitled-Notepad"

' Part Three: Save with the file name you entered

Wshshell.sendkeys "^s"
Wscript.Sleep 300
Wshshell.sendkeys Txtfilename
Wscript.Sleep 300
Wshshell.sendkeys '%s '
Wscript.Sleep Autosavetime
' Part Four: automatic timing disk
While Wshshell.appactivate (Txtfilename) =true
Wshshell.sendkeys "^s"
Wscript.Sleep Autosavetime
Wend
Wscript.Quit
----------------------------------------------------
Frozen, hey!
DIM WshShell
SET Wshshell=wscript. CreateObject ("WSCRIPT.") SHELL ")
' WshShell. RUN ""
' WSCRIPT. Sleep 1000
WshShell. SENDKEYS ' {ENTER} '
' WSCRIPT. Sleep 1000
WshShell. SENDKEYS ' {ENTER} '
' WSCRIPT. Sleep 1000
WshShell. SENDKEYS ' {ENTER} '
' WSCRIPT. Sleep 1000
WshShell. SENDKEYS ' {ENTER} '
' WSCRIPT. Sleep 1000
WshShell. SENDKEYS ' {ENTER} '
----------------------------------------------------

the timer shuts down the machine

Dim WshShell
Set wshshell=wscript.createobject ("Wscript.Shell")
Wscript.Sleep 2000
Wshshell.run "Shutdown-r-T 120"
Wscript.Sleep 6000
Wshshell.run "Shutdown-a

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.